android.database.sqlite.SQLiteException运行我的应用程序 [英] android.database.sqlite.SQLiteException running my app

查看:255
本文介绍了android.database.sqlite.SQLiteException运行我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class DBhandle {

private static final String DATABASE_NAME = "restaurantdatabase";
private static final int DATABASE_VERSION = 1;
final Context context;
private SQLiteDatabase ourDatabase;
DatabaseHelper dbHelper;


//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";
   public class DatabaseHelper extends SQLiteOpenHelper{

    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

    }

   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 void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS" + CUSTINFO_TABLE_NAME);
        onCreate(db);
        }

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();
            }

当我运行我的应用程序也与此消息android.database.sqlite.SQLiteException崩溃:没有这样的表:CUSTINFO_TABLE_NAME(code 1):在编制:INSERT INTO CUSTINFO_TABLE_NAME(cust_phone,CUST_NAME,cust_address,CUST_EMAIL )VALUES(?,?,?,?)`

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 (?,?,?,?)"`

推荐答案

卸载应用程序completelty并再次运行。您可以通过设置>应用程序卸载应用程序>单击您要卸载的应用程序>卸载,无论是在手机还是AVD运行 有时候,这个问题也面。

uninstall application completelty and run again. You can uninstall app by going to settings > apps > click on app you want to uninstall > uninstall, whether running on phone or AVD Sometimes this problem also surfaces.

这篇关于android.database.sqlite.SQLiteException运行我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆