我有一个活动,在其中我正在尝试根据某些条件获取数据列表。这个selectsome()函数在SQLiteOpenHelper子类中。
MyDBHandler dbhelper = new MyDBHandler(this);
Cursor cursor;
cursor = dbhelper.selectSome(value);
在类MyDBHelper.java中
public Cursor selectSome(String arg)
{
String columns[]=new String[]{"_id","_hotelname","_city","_imageSrc","_rent","_address"};
String selarg[]={arg};
Cursor c=db.query(TABLE_NAME,columns,"city = ?",selarg, null,null,null);
return c;
}
我遇到了这个错误,请帮忙解决。
09-01 18:08:00.394 E/AndroidRuntime( 6246): FATAL EXCEPTION: main
09-01 18:08:00.394 E/AndroidRuntime( 6246): Process: com.example.hari.testapp, PID: 6246
09-01 18:08:00.394 E/AndroidRuntime( 6246): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hari.testapp/com.example.hari.testapp.HotelList}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.query(java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String)' on a null object reference
09-01 18:08:00.394 E/AndroidRuntime( 6246): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at android.app.ActivityThread.access$800(ActivityThread.java:151)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at android.os.Handler.dispatchMessage(Handler.java:102)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at android.os.Looper.loop(Looper.java:135)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at android.app.ActivityThread.main(ActivityThread.java:5257)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at java.lang.reflect.Method.invoke(Native Method)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at java.lang.reflect.Method.invoke(Method.java:372)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
09-01 18:08:00.394 E/AndroidRuntime( 6246): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
09-01 18:08:00.394 E/AndroidRuntime( 6246): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.database.Cursor android.database.sqlite.SQLiteDatabase.query(java.lang.String, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String, java.lang.String, java.lang.String)' on a null object reference
09-01 18:08:00.394 E/AndroidRuntime( 6246): at com.example.hari.testapp.databaseFiles.MyDBHandler.selectSome(MyDBHandler.java:113)