我在getReadbleDatabase
获取了一个nullpointer异常 public List<Offer> getOffers(String offer_category)
{
db = this.getReadableDatabase();
String sql = "select * from offer_db "+TABLE_OFFER + " where "+ OFFER_CATEGORY+ " is "+ offer_category;
Cursor cur = db.rawQuery(sql,null);
cur.moveToFirst();
}
这里是logcat数据
引起:java.lang.NullPointerException at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224) 在 android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188) 在 com.example.shreyfrapp.DatabaseHandler.getOffers(DatabaseHandler.java:61) 在com.example.shreyfrapp.FragmentTab1.onCreate(FragmentTab1.java:39) 在android.app.Fragment.performCreate(Fragment.java:1678)at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:859) 在 android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062) 在android.app.BackStackRecord.run(BackStackRecord.java:684)at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447) 在android.app.Activity.performStart(Activity.java:5240)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2168) 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 在android.app.ActivityThread.access $ 800(ActivityThread.java:135)at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1196) 在android.os.Handler.dispatchMessage(Handler.java:102)at android.os.Looper.loop(Looper.java:136)at android.app.ActivityThread.main(ActivityThread.java:5021)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:515)at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:827) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)at dalvik.system.NativeStart.main(原生方法)
答案 0 :(得分:0)
以大写字母提供查询,并在“是”的位置尝试“=”。为什么你在选择查询中将光标移动到第一位?