I'm using JSON
and database to get some values and set them into listviews. JSON
objects are ok but when I try to get values from database(cursor objects) and set them into ArrayList, it gives NullPointerException
.
ArrayList<String> stringName,stringAddress,stringCapacity;
...
...
...
cursor_restnames = db.getRestNames("Ankara");
if (cursor_restnames.moveToFirst()) {
for (cursor_restnames.moveToFirst(); !cursor_restnames.isAfterLast(); cursor_restnames.moveToNext()) {
System.out.println("aaaaa "+cursor_restnames.getString(cursor_restnames.getColumnIndex("name")).toString()); // I can see the cursor object in logcat which is "aspava".
stringName.add(cursor_restnames.getString(cursor_restnames.getColumnIndex("name")).toString()); // I got error here which is NullPointerException but as I mentioned it is not null, it has "aspava" string.
}
cursor_restnames.close();
}
My DBadapter has getRestNames function which is;
public Cursor getRestNames(String city) {
Cursor myCursor = db.rawQuery("select name from rest where city='"+city+"'", null);
if (myCursor != null) {
myCursor.moveToFirst();
}
return myCursor;
}
If these code snippets will not help, I can write down the whole project. Thanks for help and if there are any mistakes about my English, I'm sorry.