糖ORM无法创建表

时间:2016-02-07 09:20:29

标签: android sugarorm

android.database.sqlite.SQLiteException:没有这样的表:USER(代码1):,同时编译:SELECT * FROM USER WHERE id =?限制1

Android清单

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SET_DEBUG_APP" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"   />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name="com.orm.SugarApp"
        >
        <meta-data android:name="DATABASE" android:value="AndroidDB.db" />
        <meta-data android:name="VERSION" android:value="5" />
        <meta-data android:name="QUERY_LOG" android:value="true" />
        <meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="com.example" />

用户类

package Model.DB;
import com.orm.SugarRecord;

public class User extends SugarRecord{
    public String UserId ;
    public String UserName ;
    public String Password ;
    public String FirstName ;
    public String LastName ;

    public User() {}
}

Build.gardle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.github.satyan:sugar:1.4'
    compile 'com.google.code.gson:gson:2.5'
}

登录活动

User user = User.findById(User.class, (long) 1);

1 个答案:

答案 0 :(得分:0)

包名必须设置为Model.DB(使用SugarRecord扩展)

<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="Model.DB" />