我正在尋找我的數據庫數量和天氣它在它的存在與否,並返回一個布爾值,但查詢總是給我當它運行一個空指針異常空指針時,查詢數據庫
查詢
public boolean getPhone(String where){
Cursor cur = db.query(DATABASE_TABLE, new String [] {ID,PHONE_NUMBER},PHONE_NUMBER + "='" + where + "'",null,null,null,null); //fails here at the query
Log.v("Cursor", cur.toString());
String test = null;
if(cur.moveToFirst()){
do{
test = cur.getString(cur.getColumnIndex(PHONE_NUMBER));
Log.v("ContactDB", test);
}while(cur.moveToNext());
return true;
}
return false;
}
實施
ContactDB db = new ContactDB(arg0);
boolean dbNumber = db.getPhone(from);//searchNumber(arg0,from);
if(dbNumber == true){
//if number exists do stuff
}else{
//if number does not exist do other stuff
}
它始終未能在查詢
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): FATAL EXCEPTION: main
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): java.lang.RuntimeException: Unable to start receiver com.app.notifyme.SmsReciever: java.lang.NullPointerException
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1805)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:981)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at android.os.Handler.dispatchMessage(Handler.java:99)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at android.os.Looper.loop(Looper.java:123)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at java.lang.reflect.Method.invokeNative(Native Method)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at java.lang.reflect.Method.invoke(Method.java:507)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at dalvik.system.NativeStart.main(Native Method)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): Caused by: java.lang.NullPointerException
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at com.app.notifyme.ContactDB.getPhone(ContactDB.java:87)
03-16 11:57:06.522: ERROR/AndroidRuntime(28579): at com.app.notifyme.SmsReciever.onReceive(SmsReciever.java:55)
一十一月3日至16日:57:06.522:ERROR/AndroidRuntime(28579):在android.app.ActivityThread.handleReceiver(ActivityThread.java:1794)
ContactDB.java中的第87行在哪裏? – 2011-03-16 16:59:21