我创建了一个表单,应该由我的应用程序中的用户填充,一些变量是数字和一些布尔值,来自用户的数据将转到我已经创建的数据库。 我制作了checkBox' s boolean(true / false)和edittext的数字(int)。出于某种原因,它给了我一个例外,以及很多崩溃。
以下是我的一些代码:
public void addArea(View view) {
Area area = new Area();
SQLiteDatabase areasDB = openOrCreateDatabase("AREA_DATABASE.sqlite", MODE_PRIVATE, null);
areasDB.execSQL("CREATE TABLE IF NOT EXISTS areas_table(name TEXT, smoking_area INTEGER" +
"outside_or_inside INTEGER, num_of_tables INTEGER" +
"num_of_diners INTEGER)");
area.setName(areaName.getText().toString());
name = areaName.getText().toString();
outside = chkOut.isChecked();
inside = chkIn.isChecked();
smokingArea = chkSmoking.isChecked();
Integer.parseInt(numOFTables = editNumTables.getText().toString());
Integer.parseInt(numOFDiners = maxDiners.getText().toString());
if (areaName.getText().toString().isEmpty()||
editNumTables.getText().toString().isEmpty() ||
maxDiners.getText().toString().isEmpty()){
AlertDialog alertDialog = new AlertDialog.Builder(Area_creating_activity.this).create();
alertDialog.setTitle("Oops,");
alertDialog.setMessage("You forgot to fill something");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
} else {
areasDB.execSQL("INSERT INTO areas_table VALUES('" + name + "','" + outside + "','" + inside+ "','" + smokingArea + "','"
+ numOFTables + "','" + numOFDiners + "')");
AlertDialog alertSucsess = new AlertDialog.Builder(Area_creating_activity.this).create();
alertSucsess.setTitle("Congrats,");
alertSucsess.setMessage(name + " Has been created");
alertSucsess.setButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivity(new Intent(getApplicationContext(), Activity_Zone.class));
}
});
alertSucsess.show();
}
areasDB.close();
}
我得到的一个错误:
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3846)
at android.view.View.performClick(View.java:4478)
at android.view.View$PerformClick.run(View.java:18698)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3841)
at android.view.View.performClick(View.java:4478)
at android.view.View$PerformClick.run(View.java:18698)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.mika.waiter.Area_creating_activity.addArea(Area_creating_activity.java:58)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3841)
at android.view.View.performClick(View.java:4478)
at android.view.View$PerformClick.run(View.java:18698)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)