我在列应用程序中有错误无法从表android

时间:2017-07-06 13:30:06

标签: android sqlite

public void onCreate(SQLiteDatabase db) {
   String CREATE_TABLE= "CREATE TABLE " + Constants.TABLE1_NAME + "(" +
           Constants.KEY_ID + " INTEGER PRIMARY KEY, "+Constants.EMP_NAME+" Text, " + Constants.PHONE_NUMBER_NAME+" TEXT, " + Constants.EMP_ID+" INT ); ";
    db.execSQL(CREATE_TABLE);
}

public int getEmpId(){
    int EmpId=0;
    SQLiteDatabase db=this.getReadableDatabase();

    String query="SELECT "+Constants.EMP_ID +" FROM "+Constants.TABLE1_NAME;
    Cursor cursor=db.rawQuery(query,null);
    if(cursor.moveToFirst())
    {EmpId=cursor.getInt(0);}

    cursor.close();
    db.close();

    return EmpId;

}
  

android.database.sqlite.SQLiteException:没有这样的列:id(代码1):   ,同时编译:SELECT id FROM info                                                                                                    在   android.database.sqlite.SQLiteConnection.nativePrepareStatement(母语   方法)                                                                                                    在   android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)                                                                                                    在   android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)                                                                                                    在   android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)                                                                                                    在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58)                                                                                                    在android.database.sqlite.SQLiteQuery。(SQLiteQuery.java:37)                                                                                                    在   android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)                                                                                                    在   android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)                                                                                                    在   android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1255)                                                                                                    at Data.DatabaseHandeler $ override.getEmpId(DatabaseHandeler.java:61)                                                                                                    在   Data.DatabaseHandeler $ override.access $讯(DatabaseHandeler.java)                                                                                                    在Data.DatabaseHandeler.getEmpId(DatabaseHandeler.java:0)                                                                                                    在   imageview.example.maged.taskforseautomation.MainActivity $ override.suresignin(MainActivity.java:60)                                                                                                    在   imageview.example.maged.taskforseautomation.MainActivity $ override.onClick(MainActivity.java:75)                                                                                                    在   imageview.example.maged.taskforseautomation.MainActivity $ override.access $讯(MainActivity.java)                                                                                                    在   imageview.example.maged.taskforseautomation.MainActivity.onClick(MainActivity.java:0)                                                                                                    在android.view.View.performClick(View.java:4780)                                                                                                    在android.view.View $ PerformClick.run(View.java:19866)                                                                                                    在android.os.Handler.handleCallback(Handler.java:739)                                                                                                    在android.os.Handler.dispatchMessage(Handler.java:95)                                                                                                    在android.os.Looper.loop(Looper.java:135)                                                                                                    在android.app.ActivityThread.main(ActivityThread.java:5254)                                                                                                    at java.lang.reflect.Method.invoke(Native Method)                                                                                                    在java.lang.reflect.Method.invoke(Method.java:372)                                                                                                    在   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)                                                                                                    在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

2 个答案:

答案 0 :(得分:0)

在你的表中,你没有创建colum id,而是在SQL查询中指定,这就是为什么它显示错误。 尝试登录你的表创建查询并注意清楚

答案 1 :(得分:0)

将此作为您的select语句使用 String query="SELECT "+Constants.KEY_ID +" FROM "+Constants.TABLE1_NAME;

数据库架构中没有列Constants.EMP_ID。检查Create table命令。