Attempting to insert data into an sqLite database upon button OnClick is resulting in the following exception:
Logcat:
03-24 17:54:14.773: D/AndroidRuntime(1579): --------- beginning of crash
03-24 17:54:14.774: E/AndroidRuntime(1579): FATAL EXCEPTION: main
03-24 17:54:14.774: E/AndroidRuntime(1579): Process: com.snappy.stevekamau.cosmeticsapp, PID: 1579
03-24 17:54:14.774: E/AndroidRuntime(1579): java.lang.IllegalStateException: Could not execute method of the activity
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.view.View$1.onClick(View.java:4007)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.view.View.performClick(View.java:4756)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.view.View$PerformClick.run(View.java:19749)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.os.Handler.handleCallback(Handler.java:739)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.os.Handler.dispatchMessage(Handler.java:95)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.os.Looper.loop(Looper.java:135)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.app.ActivityThread.main(ActivityThread.java:5221)
03-24 17:54:14.774: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Native Method)
03-24 17:54:14.774: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Method.java:372)
03-24 17:54:14.774: E/AndroidRuntime(1579): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
03-24 17:54:14.774: E/AndroidRuntime(1579): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-24 17:54:14.774: E/AndroidRuntime(1579): Caused by: java.lang.reflect.InvocationTargetException
03-24 17:54:14.774: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Native Method)
03-24 17:54:14.774: E/AndroidRuntime(1579): at java.lang.reflect.Method.invoke(Method.java:372)
03-24 17:54:14.774: E/AndroidRuntime(1579): at android.view.View$1.onClick(View.java:4002)
03-24 17:54:14.774: E/AndroidRuntime(1579): ... 10 more
03-24 17:54:14.774: E/AndroidRuntime(1579): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.widget.TextView.getText()' on a null object reference
03-24 17:54:14.774: E/AndroidRuntime(1579): at com.snappy.stevekamau.cosmeticsapp.Details.run(Details.java:83)
03-24 17:54:14.774: E/AndroidRuntime(1579): ... 13 more
DBHelper:
public class DBHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "MyDBName.db";
public static final String CONTACTS_TABLE_NAME = "contacts";
public static final String CONTACTS_COLUMN_ID = "id";
public static final String CONTACTS_COLUMN_NAME = "name";
public static final String CONTACTS_COLUMN_EMAIL = "email";
public static final String CONTACTS_COLUMN_PHONE = "phone";
private HashMap hp;
public DBHelper(Context context)
{
super(context, DATABASE_NAME , null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(
"create table contacts " +
"(id integer primary key, title text,phone text,email text)"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS contacts");
onCreate(db);
}
public boolean insertContact (String name, String phone, String email)
{
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("title", name);
contentValues.put("amount", phone);
contentValues.put("description", email);
db.insert("contacts", null, contentValues);
return true;
}
...
}
MyBasket.java:
public class MyBasket extends ActionBarActivity {
private ListView obj;
DBHelper mydb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_basket);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeButtonEnabled(true);
...
}
Details.java:
public class Details extends ActionBarActivity {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
...
}
public void run(View view) {
...
}
...
}