Sugar ORM 1.4 E / SQLiteLog:(1)没有这样的表:COURTS

时间:2016-07-07 19:02:12

标签: android sqlite orm sugarorm

对于一些原因,SUgar ORM并没有创建我的实体。我试图禁用进度运行,增加数据库版本,完全卸载应用程序,但似乎没有工作。我正在使用糖ORM版本1.4。这是我得到的错误日志

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

2 个答案:

答案 0 :(得分:0)

SugarORM与VERSION有一些奇怪的问题。尝试删除整个应用,再次尝试将VERSION更改为2。它帮助了我。

答案 1 :(得分:0)

问题在于糖ORM的版本。我尝试更改数据库版本并且它没有工作但是只要我将糖ORM从1.4更改为1.5,它就有效了