samedi 25 avril 2015

android - java string.format()


Coming from C# i'm trying to port what I know over into Android.

I'm basically trying to do a string.Format with 2 variables.

Here is the code. val1 = "HelloWorld" va2 = 11

EditText edt = (EditText)findViewById(R.id.main_studentName);
    String val = edt.getText().toString();

    EditText edt2 = (EditText)findViewById(R.id.main_studentAge);
    String val2 = edt2.getText().toString();

    String sqlSampleString = String.format("insert into Students(StudentName,StudentAge) Values('%1$',%2$)", val,val2);
    myDatabase.execSQL(sqlSampleString);

Here is the error in LogCat

04-25 10:44:47.858    9701-9701/com.example.mycomp.buildingproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.mycomp.buildingproject, PID: 9701
    java.lang.IllegalStateException: Could not execute method of the activity

Aucun commentaire:

Enregistrer un commentaire