I have a ListView that fills from existing database, when user clicked on each item, one of the other columns, should be displayed on second Activity (Like dictionary App
)
But I can't execute any queries on second activity.
I'm using SqliteAssetHelper
library.
Database class:
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "database.db";
private static final int DATABASE_VERSION = 1;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}
On the first activity, listView filled from the database:
private void fillFromDb() {
G.itemLists.clear();
Cursor cursor = mydb.rawQuery("select * from test order by title limit 0,50 ", null);
while (cursor.moveToNext()) {
StructNote test1 = new StructNote();
test1.title = cursor.getString(cursor.getColumnIndex("title"));
G.itemLists.add(test1);
}
cursor.close();
mydb.close();
adapter.notifyDataSetChanged();
}
but the problem is in the second activity; I can't execute any queries!
public class ActivityResult extends Activity {
private MyDatabase MyDataBase;
public SQLiteDatabase mydb;
@Override
protected void onResume() {
G.currentActivity = this;
super.onResume();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
Cursor cursor = mydb.rawQuery("SELECT * FROM test ", null);
while (cursor.moveToNext()) {
try {
Log.i("LOG", cursor.getString(cursor.getColumnIndex("title")));
}
catch (Exception e) {}
}
cursor.close();
mydb.close();
}
}
logcat: NullPointerException
Many thanks...
My question was not duplicate! Other answers that I found about NullPointerException were not fully addressing my question :)
Because my problem and solution was only in use of SqliteAssetHelper
library, that I couldn't find anything about it ;)