I made a form which should be filled by a user in my application, some of the variables numeric and some boolean , the data thats coming from the user is going to db that I've created. I made the checkBox's boolean(true/false) , and edittext's numeric (int) . For some reason, it gives me an exception, and a lot of crashes.
Here are some of my code :
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();
}
one of the errors i get :
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)
Aucun commentaire:
Enregistrer un commentaire