我在AndroidManifest.xml上配置了ActiveAndroid,如下所述:
<application
android:name="com.xxx.xxxx.XXXApplication"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
<meta-data
android:name="AA_DB_NAME"
android:value="MyDB.db" />
<meta-data
android:name="AA_DB_VERSION"
android:value="2" />
...
</application>
申请类:
public class XXXApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
ActiveAndroid.initialize(this);
}
}
模式类是:
@Table(name = "Routes")
public class Route extends Model {
...
public static List<Routes> all(){
return new Select().from(Route.class).execute();
}
}
Ps:我按照文档说明: https://github.com/pardom/ActiveAndroid/wiki/Getting-started
当调用Routes.all()时出现此错误:
尝试在未准备的类中执行代码'Lbr / com / xxx / xxx / xxxx / models / Route;'
完整筹码是:
03-08 16:41:56.505: E/dalvikvm(23688): ERROR: tried to execute code in unprepared class 'Lbr/com/xxx/xxx/xxxx/models/Route;' (5)
03-08 16:41:56.505: I/dalvikvm(23688): "main" prio=5 tid=1 RUNNABLE
03-08 16:41:56.505: I/dalvikvm(23688): | group="main" sCount=0 dsCount=0 obj=0x41800508 self=0x417efce0
03-08 16:41:56.505: I/dalvikvm(23688): | sysTid=23688 nice=0 sched=0/0 cgrp=apps handle=1075560240
03-08 16:41:56.505: I/dalvikvm(23688): | schedstat=( 1596851683 269907401 1132 ) utm=148 stm=11 core=0
03-08 16:41:56.505: I/dalvikvm(23688): at com.xxxx.models.Route.all(Route.java:-1)
03-08 16:41:56.505: I/dalvikvm(23688): at com.xxxx.activities.SavedRoutesActivity.onCreate(SavedRoutesActivity.java:-1)
03-08 16:41:56.505: I/dalvikvm(23688): at com.xxxx.activities.SavedRoutesActivity_.onCreate(SavedRoutesActivity_.java:24)
03-08 16:41:56.505: I/dalvikvm(23688): at android.app.Activity.performCreate(Activity.java:5206)
03-08 16:41:56.505: I/dalvikvm(23688): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
03-08 16:41:56.505: I/dalvikvm(23688): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
03-08 16:41:56.505: I/dalvikvm(23688): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
03-08 16:41:56.505: I/dalvikvm(23688): at android.app.ActivityThread.access$600(ActivityThread.java:140)
03-08 16:41:56.505: I/dalvikvm(23688): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
03-08 16:41:56.505: I/dalvikvm(23688): at android.os.Handler.dispatchMessage(Handler.java:99)
03-08 16:41:56.505: I/dalvikvm(23688): at android.os.Looper.loop(Looper.java:137)
03-08 16:41:56.505: I/dalvikvm(23688): at android.app.ActivityThread.main(ActivityThread.java:4898)
03-08 16:41:56.505: I/dalvikvm(23688): at java.lang.reflect.Method.invokeNative(Native Method)
03-08 16:41:56.505: I/dalvikvm(23688): at java.lang.reflect.Method.invoke(Method.java:511)
03-08 16:41:56.505: I/dalvikvm(23688): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-08 16:41:56.505: I/dalvikvm(23688): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-08 16:41:56.505: I/dalvikvm(23688): at dalvik.system.NativeStart.main(Native Method)
03-08 16:41:56.505: E/dalvikvm(23688): VM aborting
03-08 16:41:56.505: A/libc(23688): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 23688 (o.mobile.xxxx)
答案 0 :(得分:5)
这已经很晚了,但可以帮助那些面临同样问题的人。 此问题仅发生在调试模式中,以解决它:
答案 1 :(得分:1)
你还记得为Route写一个标准的构造函数吗? E. g。
public Route(){
super();
}
如果您有自己的Application类,则必须从com.activeandroid.app.Application
:
public class Application extends com.activeandroid.app.Application {
…
}
如果这没有帮助,请发布路线签名。