2016-11-29 70 views
-3
@Override 
     public void onCreate(SQLiteDatabase db) { 
      // TODO Auto-generated method stub 
      db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + 
          KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + 
          KEY_NAME + " TEXT NOT NULL, " + 
          KEY_SKILL + " TEXT NOT NULL" + 
          KEY_COUNTY + "TEXT NOT NULL);" 
      ); 

      db.execSQL(" CREATE TABLE " + DATABASE_BANK + " ("+      //SQL CREATE statement for Bank table 
        KEY_ROWID + " INTEGER NOT NULL PRIMARY KEY);"); 
     } 

在創建方法中,我創建了這個表,但是當我運行應用程序時,它告訴我,關鍵縣有什麼問題。下面我會發布logcat。它說:「沒有這樣的列:business_county」,唯一的地方我有這樣的引用在這裏沒有這樣的列存在,Android Studio

public static final String KEY_ROWID = "_id"; 
    public static final String KEY_NAME = "persons_name"; 
    public static final String KEY_SKILL = "persons_skill"; 
    public static final String KEY_COUNTY = "business_county"; 

但是我認爲,如果你把花生醬例如在括號沒有問題,那是無論你通緝。

的logcat:

11-29 23:22:41.343 23491-23491/com.example.tl.firstdb W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 
11-29 23:22:41.344 23491-23491/com.example.tl.firstdb W/ViewRootImpl: Dropping event due to root view being removed: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=218.31485, y[0]=200.40204, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=185996190, downTime=185996177, deviceId=6, source=0x1002 } 
11-29 23:22:41.344 23491-23491/com.example.tl.firstdb W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 
11-29 23:22:42.101 23491-23491/com.example.tl.firstdb I/System.out: The Context from skillslevel class com.example.tl.firstdb.SQLView 
11-29 23:22:42.105 23491-23491/com.example.tl.firstdb E/SQLiteLog: (1) no such column: business_county 
11-29 23:22:42.106 23491-23491/com.example.tl.firstdb D/AndroidRuntime: Shutting down VM 
11-29 23:22:42.107 23491-23491/com.example.tl.firstdb E/AndroidRuntime: FATAL EXCEPTION: main 
                     Process: com.example.tl.firstdb, PID: 23491 
                     java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.example.tl.firstdb/com.example.tl.firstdb.SQLView}: android.database.sqlite.SQLiteException: no such column: business_county (code 1): , while compiling: SELECT _id, persons_name, persons_skill, business_county FROM peopleTable 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) 
                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5443) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
                     Caused by: android.database.sqlite.SQLiteException: no such column: business_county (code 1): , while compiling: SELECT _id, persons_name, persons_skill, business_county FROM peopleTable 
                      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 
                      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887) 
                      at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498) 
                      at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 
                      at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) 
                      at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37) 
                      at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 
                      at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316) 
                      at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163) 
                      at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034) 
                      at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1202) 
                      at com.example.tl.firstdb.SkillsLevel.getData(SkillsLevel.java:107) 
                      at com.example.tl.firstdb.SQLView.onCreate(SQLView.java:37) 
                      at android.app.Activity.performCreate(Activity.java:6245) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)  
                      at android.app.ActivityThread.-wrap11(ActivityThread.java)  
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)  
                      at android.os.Handler.dispatchMessage(Handler.java:102)  
                      at android.os.Looper.loop(Looper.java:148)  
                      at android.app.ActivityThread.main(ActivityThread.java:5443)  

回答

1

你缺少一個逗號在創建表語句,TEXT NOT NULLKEY_COUNTY列名之間。修復此錯字之後,您需要通過清除設置>應用程序中的應用程序數據或卸載並重新安裝來刪除數據庫。

0

你錯過keyskill後逗號,你需要把列名和列類型..Like這之間的空間。我在這裏提到的& NBSP .. KEY_COUNTY +「& nbspTEXT NOT NULL);」

相關問題