我想从我的数据库处理程序文件中使用下面给定的删除功能。当我实现它时,javaNullpointerException 即将到来。我肯定错过了一些东西。
删除功能:
// Deleting single contact
public void deleteContact(Contact contact) {
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CONTACTS, KEY_ID + " = ?",new String[] { String.valueOf(contact.getID()) });
db.close();
}
我正在尝试用作:
DatabaseHandler db = new DatabaseHandler(this);
Contact pm = null;
Intent i;
i = getIntent();
pm._id= i.getExtras().getInt("id");
pm._name = i.getExtras().getString("name");
pm._phone_number = i.getExtras().getString("phone_number");
// **Some problem is here I am not getting it
db.deleteContact(pm);
Toast.makeText(getApplicationContext(),"Deleted..",Toast.LENGTH_SHORT).show();
日志猫:
08-19 01:15:00.726: E/AndroidRuntime(12657): FATAL EXCEPTION: main
08-19 01:15:00.726: E/AndroidRuntime(12657): java.lang.NullPointerException
08-19 01:15:00.726: E/AndroidRuntime(12657): at com.parth.targetthebudget.ViewContact$ListAdapter$2$1.onClick(ViewContact.java:151)
08-19 01:15:00.726: E/AndroidRuntime(12657): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:163)
08-19 01:15:00.726: E/AndroidRuntime(12657): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 01:15:00.726: E/AndroidRuntime(12657): at android.os.Looper.loop(Looper.java:130)
08-19 01:15:00.726: E/AndroidRuntime(12657): at android.app.ActivityThread.main(ActivityThread.java:3687)
08-19 01:15:00.726: E/AndroidRuntime(12657): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 01:15:00.726: E/AndroidRuntime(12657): at java.lang.reflect.Method.invoke(Method.java:507)
08-19 01:15:00.726: E/AndroidRuntime(12657): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-19 01:15:00.726: E/AndroidRuntime(12657): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-19 01:15:00.726: E/AndroidRuntime(12657): at dalvik.system.NativeStart.main(Native Method)