如何在Activeandroid中禁用模型扫描

时间:2014-05-28 08:56:36

标签: android database activeandroid

我想使用AA_MODEL标记在AndroidManifest.xml文件中定义我的模型类并禁用自动搜索。因为当前我在应用程序启动时遇到错误类似于:

Couldn't create class.
    java.lang.ClassNotFoundException: android.support.v4.print.PrintHelperKitkat$1
            at java.lang.Class.classForName(Native Method)
            at java.lang.Class.forName(Class.java:204)
            at com.activeandroid.ModelInfo.scanForModelClasses(Unknown Source)
            at com.activeandroid.ModelInfo.scanForModel(Unknown Source)
            at com.activeandroid.ModelInfo.<init>(Unknown Source)
            at com.activeandroid.Cache.initialize(Unknown Source)
            at com.activeandroid.ActiveAndroid.initialize(Unknown Source)
            at com.activeandroid.ActiveAndroid.initialize(Unknown Source)
            at com.company.myapp.app.MyAppApplication.onCreate(Unknown Source)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4684)
            at android.app.ActivityThread.access$1400(ActivityThread.java:159)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1376)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at dalvik.system.NativeStart.main(Native Method)

怎么做得好?你能告诉我一个定义明确的AA_MODEL标签的例子吗?

2 个答案:

答案 0 :(得分:13)

您可以在Application对象中定义模型。此禁用模型自动搜索。

public class ShantApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();

    initializeDB();
}

protected void initializeDB() {
    Configuration.Builder configurationBuilder = new Configuration.Builder(this);
    configurationBuilder.addModelClasses(Test.class);
    configurationBuilder.addModelClasses(ShoppingList.class);
    configurationBuilder.addModelClasses(ShoppingListItem.class);
    configurationBuilder.addModelClasses(ArticleInfoModel.class);

    ActiveAndroid.initialize(configurationBuilder.create());
}

}

答案 1 :(得分:5)

在Androidmanifest文件中使用XML文件:

<meta-data
 android:name="AA_MODELS"
 android:value="your.package.ModelA,your.package.ModelB,your.package.ModelC"/>