### database class ###
public class DBhandle {
//table name
private static final String CUSTINFO_TABLE_NAME= "Custinfo";
//login table column name
public final static String C_ID = "_id";
public final static String C_NAME = "cust_name";
public final static String C_PHONE = "cust_phone";
public final static String C_EMAIL = "cust_email";
public final static String C_ADDR = "cust_address";
db.execSQL("CREATE TABLE " + CUSTINFO_TABLE_NAME + " (" + C_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + C_NAME
+ " TEXT NOT NULL, " + C_PHONE + " TEXT NOT NULL, " + C_EMAIL
+ " TEXT NOT NULL, " + C_ADDR + " TEXT NOT NULL);"
);
public long addCustInfo(String custname, String custno, String custemail,String custaddress) {
ContentValues newValues = new ContentValues();
// Assign values for each row.
newValues.put("cust_name", custname);
newValues.put("cust_phone", custno);
newValues.put("cust_email", custemail);
newValues.put("cust_address", custaddress);
// Insert the row into your table
return ourDatabase.insert(CUSTINFO_TABLE_NAME, null, newValues);
}
### data class ###
public void onClick(View arg0) {
//Intent saveintent=new Intent(getApplicationContext(),)
String custname=edittextcust_name.getText().toString();
String custno=edittextcust_no.getText().toString();
String custemail=edittextcust_email.getText().toString();
String custaddress=edittextcust_address.getText().toString();
if(custname.equals("")||custno.equals("")||custemail.equals("")||custaddress.equals(""))
{
Toast.makeText(Custentry.this, "field vacant", Toast.LENGTH_LONG).show();
}
else
{
dbhandle.addCustInfo(custname, custno, custemail, custaddress);
Toast.makeText(Custentry.this, " welcome" +custname, Toast.LENGTH_LONG).show();
}
when i run my app it crashes with this message "android.database.sqlite.SQLiteException: no such table: CUSTINFO_TABLE_NAME (code 1): , while compiling: INSERT INTO CUSTINFO_TABLE_NAME(cust_phone,cust_name,cust_address,cust_email) VALUES (?,?,?,?)"
Aucun commentaire:
Enregistrer un commentaire