2016-07-07 33 views
0

對於某些reaso SUgar ORM不會創建我的實體。我試圖禁用完好的運行,增加了數據庫版本,完全卸載應用程序,但似乎沒有工作。我正在使用糖ORM版本1.4。這裏是錯誤日誌,我得到Sugar ORM 1.4 E/SQLiteLog:(1)沒有這樣的表格:COURTS

07-07 21:48:01.575 31907-31907/com.globalsites.lms E/SQLiteLog: (1) no such table: COURTS 
07-07 21:48:01.577 31907-31907/com.globalsites.lms D/AndroidRuntime: Shutting down VM 
07-07 21:48:01.578 31907-31907/com.globalsites.lms E/AndroidRuntime: FATAL EXCEPTION: main 
                    Process: com.globalsites.lms, PID: 31907 
                    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.globalsites.lms/com.globalsites.lms.Unsubscribed.UnsubscribedMainActivity}: android.database.sqlite.SQLiteException: no such table: COURTS (code 1): , while compiling: INSERT OR REPLACE INTO COURTS(TYPE,ID,NAME,LOCATION) VALUES (?,?,?,?) 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2539) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2619) 
                     at android.app.ActivityThread.access$700(ActivityThread.java:183) 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1485) 
                     at android.os.Handler.dispatchMessage(Handler.java:111) 
                     at android.os.Looper.loop(Looper.java:194) 
                     at android.app.ActivityThread.main(ActivityThread.java:5668) 
                     at java.lang.reflect.Method.invoke(Native Method) 
                     at java.lang.reflect.Method.invoke(Method.java:372) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758) 
                     Caused by: android.database.sqlite.SQLiteException: no such table: COURTS (code 1): , while compiling: INSERT OR REPLACE INTO COURTS(TYPE,ID,NAME,LOCATION) VALUES (?,?,?,?) 
                     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 
                     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:898) 
                     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:509) 
                     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 
                     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) 
                     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) 
                     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1499) 
                     at com.orm.SugarRecord.save(SugarRecord.java:266) 
                     at com.orm.SugarRecord.save(SugarRecord.java:360) 
                     at com.globalsites.lms.Unsubscribed.UnsubscribedMainActivity.onCreate(UnsubscribedMainActivity.java:102) 
                     at android.app.Activity.performCreate(Activity.java:6155) 
                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112) 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2486) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2619)  
                     at android.app.ActivityThread.access$700(ActivityThread.java:183)  
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1485)  
                     at android.os.Handler.dispatchMessage(Handler.java:111)  
                     at android.os.Looper.loop(Looper.java:194)  
                     at android.app.ActivityThread.main(ActivityThread.java:5668)  
                     at java.lang.reflect.Method.invoke(Native Method)  
                     at java.lang.reflect.Method.invoke(Method.java:372)  
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:963)  
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:758)  
07-07 21:48:01.591 31907-31907/com.globalsites.lms I/Process: Sending signal. PID: 31907 SIG: 9 

的實體類:

package com.globalsites.lms.Models; 

import com.orm.SugarRecord; 

/** 
* Created by muoki on 7/7/2016. 
*/ 
public class Courts extends SugarRecord { 
    String name, location, type; 

    public Courts() { 
    } 

    public Courts(String name, String location, String type) { 
     this.name = name; 
     this.location = location; 
     this.type = type; 
    } 

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public String getLocation() { 
     return location; 
    } 

    public void setLocation(String location) { 
     this.location = location; 
    } 

    public String getType() { 
     return type; 
    } 

    public void setType(String type) { 
     this.type = type; 
    } 
} 

清單:

<application 
     android:allowBackup="true" 
     android:icon="@drawable/lms_logo" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme" 
     tools:replace="android:icon" 
     android:name="com.orm.SugarApp"> 
     <meta-data android:name="DATABASE" android:value="sugar_glms.db" /> 
     <meta-data android:name="VERSION" android:value="1" /> 
     <meta-data android:name="QUERY_LOG" android:value="true" /> 
     <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.globalsites.lms" /> 

     <activity 
      android:name=".SplashScreen" 
      android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".LoginActivity" 
      android:label="Login" > 

     </activity> 
     <activity 
      android:name=".RegisterActivity" 
      android:label="Register"> 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value=".LoginActivity" /> 
     </activity> 
     <activity 
      android:name=".Unsubscribed.UnsubscribedMainActivity" 
      android:label="Welcome to LMS" 
      android:theme="@style/AppTheme.NoActionBar" /> 

這該是多麼想創建一個記錄

Courts newCourt = new Courts("Milimani Law Courts","Nairobi","supreme"); 
     newCourt.save(); 

回答

0

問題出在糖ORM的版本。我試圖更改數據庫版本,它沒有工作,但只要我將糖ORM從1.4更改爲1.5,它的工作

0

SugarORM有一些奇怪的問題與VERSION。嘗試刪除整個應用程序,再次嘗試將VERSION更改爲2。它幫助了我。

+0

另一位用戶也提到了這一點https://stackoverflow.com/questions/38292116/sugarorm-error-或缺失的數據庫/ 39514488#39514488。我反覆使用版本1,沒有任何副作用,更改版本實際上對你有幫助嗎? – JakeSteam

+0

@Jake是的,它幫助了我。 SugarORM無法創建兩列簡單的表格。在我從AVD模擬器中刪除了所有內容後,將db版本更改爲2,並且一切正常。 – TomTom

相關問題