我的应用程序有两个按钮,第一个按钮用于删除用户输入的记录,第二个按钮用于删除所有记录。但是,当我想删除数据时,它显示消息
“您的申请已被强制停止”。
原文链接:https://www.f2er.com/sqlite/198357.html“您的申请已被强制停止”。
请检查我的代码,并给我一些建议。
public void deleteAll() { //sqliteDatabase db = this.getWritableDatabase(); // db.delete(TABLE_NAME,null,null); //db.execsql("delete * from"+ TABLE_NAME); db.execsql("TRUNCATE table" + TABLE_NAME); db.close(); }
和
public void delete(String id) { String[] args={id}; getWritableDatabase().delete("texts","_ID=?",args); }
03-07 15:57:07.143: ERROR/AndroidRuntime(287): Uncaught handler: thread main exiting due to uncaught exception 03-07 15:57:07.153: ERROR/AndroidRuntime(287): java.lang.NullPointerException 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at com.example.MysqLiteHelper.delete(MysqLiteHelper.java:163) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at com.example.Settings$4.onClick(Settings.java:94) -07 15:57:07.153: ERROR/AndroidRuntime(287): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:158) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at android.os.Handler.dispatchMessage(Handler.java:99) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at android.os.Looper.loop(Looper.java:123) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at android.app.ActivityThread.main(ActivityThread.java:4203) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at java.lang.reflect.Method.invokeNative(Native Method) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at java.lang.reflect.Method.invoke(Method.java:521) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 03-07 15:57:07.153: ERROR/AndroidRuntime(287): at dalvik.system.NativeStart.main(Native Method)