Any Help would be nice. Thanks in advance. This is my log --------- beginning of crash 10-09 08:32:13.574 2061-2061/com.example.asiguha.sos E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.asiguha.sos, PID: 2061
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:4020)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by:
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.view.View$1.onClick(View.java:4015)
This is My Activity
public class SettingsActivity extends ActionBarActivity {
EditText test1,test2,test3,test4;
DbOperator dboperator;
SQLiteDatabase db;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
test1= (EditText)findViewById(R.id.editText);
test2= (EditText)findViewById(R.id.editText2);
test3= (EditText)findViewById(R.id.editText3);
test4= (EditText)findViewById(R.id.editText4);
}
public void addinfo(View view)
{
String mob1= test1.getText().toString();
dboperator= new DbOperator(context);
db=dboperator.getWritableDatabase();
dboperator.adddata(mob1, db);
dboperator.close();
}
}
This is My Database Class
public class DbOperator extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "Contacts";
protected static final String FIRST_TABLE_NAME = "PhoneBook";
public static final String CREATE_FIRST_TABLE = "CREATE TABLE "
+ FIRST_TABLE_NAME
+"( _id integer primary key autoincrement, PhoneNo TEXT NOT NULL);";
public DbOperator(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_FIRST_TABLE);
Log.e("database operation","table created");
//db.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, intnewVersion)
{
}
public void adddata(String mob, SQLiteDatabase db)
{
ContentValues contentvalues= new ContentValues();
contentvalues.put("PhoneNo",mob);
db.insert(FIRST_TABLE_NAME, null, contentvalues);
Log.e("Database operation","one row added");
}
}
Aucun commentaire:
Enregistrer un commentaire