do you guys know what's the problem with this code? When I click the button to insert the data into sqlite external database. But it seems not working. The Error shows at the cv.put("name", txn.getName());
Maybe I used wrong way to write?
java page
public void onClick(View v) {
try {
SQLiteDatabase db = mSQLiteHelper.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("name", txn.getName());
cv.put("address", txn.getAddress());
cv.put("phone", txn.getPhone());
db.insert("Table1", null, cv);
db.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Here is the Error exception says
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.waiku.work2.Model.getName()' on a null object reference
this is my OOP Model, I'm a bit confused how it works. But I followed the youtube tutorial...
public class Model {
private int id;
private String name;
private String address;
private int phone;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getPhone() {
return phone;
}
public void setPhone(int phone) {
this.phone = phone;
}
}
here is my SQLite Helper
public class SQLiteHelper extends SQLiteAssetHelper {
private static final String DB_NAME = "MyExternalDatabase.db";
private static final int DATABASE_VERSION = 1;
public SQLiteHelper(Context context) {
super(context, DB_NAME, null, DATABASE_VERSION);
}