1
我想插入數據到sqlite數據庫表中的行通過填寫表單,它有錯誤,當我點擊提交按鈕。下面是一段代碼和logcat的按鈕提交到數據庫錯誤
public void callDialogConfirmation(){
AlertDialog.Builder confirm = new AlertDialog.Builder(Form.this);
confirm.setTitle("Please Confirm");
confirm.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String inputanSavings = spinner1.getSelectedItem().toString();
String tglmsk = spinner2.getSelectedItem().toString();
SharedPreferences.Editor editor = someData.edit();
editor.putString("sharedString1", inputanSavings);
editor.putString("sharedString2", tglmsk);
editor.commit();
String inputSalary = salary.getText().toString();
dbHelper.createIncome("Routine Income",inputSalary);
Intent openStartingPoint = new Intent(Form.this, MainActivity.class);
startActivity(openStartingPoint);
}});
,這裏是插入數據
public long createIncome(String l, String n) {
ContentValues initialValues = new ContentValues();
initialValues.put(RLPE, l);
initialValues.put(RNPE, n);
initialValues.put(RBPE, m); // The m is the current date with Calendar library
return mDbP.insert(INCOME_TABLE, null, initialValues);
}
這裏的我得到的錯誤很快我點擊法「提交」按鈕
07-21 22:00:39.234: E/AndroidRuntime(971): FATAL EXCEPTION: main
07-21 22:00:39.234: E/AndroidRuntime(971): java.lang.NullPointerException
07-21 22:00:39.234: E/AndroidRuntime(971): at com.diarykeuanganmahasiswa.dkm.Form$1.onClick(Form.java:64)
07-21 22:00:39.234: E/AndroidRuntime(971): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:159)
07-21 22:00:39.234: E/AndroidRuntime(971): at android.os.Handler.dispatchMessage(Handler.java:99)
07-21 22:00:39.234: E/AndroidRuntime(971): at android.os.Looper.loop(Looper.java:123)
07-21 22:00:39.234: E/AndroidRuntime(971): at android.app.ActivityThread.main(ActivityThread.java:3683)
07-21 22:00:39.234: E/AndroidRuntime(971): at java.lang.reflect.Method.invokeNative(Native Method)
07-21 22:00:39.234: E/AndroidRuntime(971): at java.lang.reflect.Method.invoke(Method.java:507)
07-21 22:00:39.234: E/AndroidRuntime(971): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
07-21 22:00:39.234: E/AndroidRuntime(971): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
07-21 22:00:39.234: E/AndroidRuntime(971): at dalvik.system.NativeStart.main(Native Method)
任何人都知道什麼似乎是問題?請幫助,謝謝
您的onClick在第64行解引用空指針。哪一行是? –
它是'dbHelper.createIncome(「Routine Income」,inputSalary);'任何想法爲什麼它是空的?投入沒有問題,不是嗎? –
其空的dbHelper。你在哪裏創建它? –