Android SQL Errors
I've been following a tutorial for working with SQL databases, I think I'm having issues with it because it has been written a while ago.
For example it had this.createDatabase which had to be replaced with this.openOrCreateDatabase, I found this with Google. There are other problems that I cannot find the solutions to: Query, Results, Next, setListAdapter all show errors.
Is this in fact the problem, that the tutorial has been created for an earlier SDK? Can someone please tell me where to go to see deprecated methods and their replacements or point out what I should be replacing the above with?
Apologies I'm just starting out with this, hopefully you understand what I mean. Help is very much appreciated.
EDIT: Tutorial is here: http://www.anddev.org/novice-tutorials-f8/working-with-the-sqlite-database-cursors-t319.html
The problems are in the code below, c.first, results.add, c.next, this.setListAdapter and most of the last line have errors
if (c.first()) {
int i = 0;
/* Loop through all Results */
do {
i++;
/* Retrieve the values of the Entry
* the Cursor is pointing to. */
String firstName = c.getString(firstNameColumn);
int age = c.getInt(ageColumn);
String ageColumName = c.getColumnName(ageColumn);
/* Add current Entry to results. */
results.add("" + i + ": " + firstName
+ " (" + ageColumName + ": " + age + ")");
} while (c.next());
}
}
} catch (FileNotFoundException e) {
} finally {
if (myDB != null)
myDB.close();
}
this.setListAdapter(new ArrayAdapter<String>(this,
开发者_JAVA百科 android.R.layout.simple_list_item_1_small, results));
} }
You can have a look at the sample notepad source NotepadProvider, NoteEditor and NoteList for implementation.
The android documentation should show which methods have been deprecated and what to replace their use with. For example, Context.clearWallpaper()
.
- SQLLite Database documentation
If you look at the documentation, in the upper right hand side of each method name it states the API level that the method was introduced in. eg. openOrCreateDatabase (String path, SQLiteDatabase.CursorFactory factory)
is since API level 1
.
If you want help with specific methods then you will need to either give us the link to the tutorial or (more preferably) post some code.
EDIT
At the very top of the tutorial you linked to it says:
:warning: Compatible for SDK version m3-xxx or older
It's now out of date. You should check the data storage page, then review the examples in the post by @TheCottonSilk
精彩评论