我想使用 Sugar ORM 1.4 ,按照This Page上的说明添加依赖
dependencies {
...
compile 'com.github.satyan:sugar:1.4'
}
Manifest.xml是
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="com.orm.SugarApp"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data android:name="DATABASE" android:value="schedule.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="org.ast.labs.schedule.entity" />
<activity
android:name=".activity.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
...
实体是
public class Appointment extends SugarRecord{
private String title;
private String clientNumber;
private String clientAddress;
public Appointment(String title, String clientNumber, String clientAddress) {
this.title = title;
this.clientNumber = clientNumber;
this.clientAddress = clientAddress;
}
....
当我尝试以这种方式在onCreate()中获取List时
private List<Appointment> mAppointmentList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAppointmentList = Appointment.listAll(Appointment.class);
TAdapter adapter = new TAdapter(LinearLayoutManager.VERTICAL, mAppointmentList);
recyclerView.setAdapter(adapter);
...
我在第行获取错误mAppointmentList = Appointment.listAll(Appointment.class);
FATAL EXCEPTION: main
Process: org.ast.labs.schedule, PID: 22377
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.ast.labs.schedule/org.ast.labs.schedule.activity.MainActivity}: android.database.sqlite.SQLiteException: no such table: APPOINTMENT (code 1): , while compiling: SELECT * FROM APPOINTMENT
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2521)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
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:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
Caused by: android.database.sqlite.SQLiteException: no such table: APPOINTMENT (code 1): , while compiling: SELECT * FROM APPOINTMENT
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.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1346)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1193)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1064)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1270)
at com.orm.SugarRecord.find(SugarRecord.java:192)
at com.orm.SugarRecord.listAll(SugarRecord.java:94)
at org.ast.labs.schedule.activity.MainActivity.onCreate(MainActivity.java:45)
at android.app.Activity.performCreate(Activity.java:6092)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
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:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
我在Android上 NOVICE 到 ORM ,非常感谢任何帮助。