How to disable scanning for model in Activeandroid

2019-01-24 11:42发布

I would like to define my model classes in AndroidManifest.xml file using AA_MODEL tag and disable auto search. Because currently I get errors when application starts similar to:

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)

How to do it properly ? Can you show me example of well defined AA_MODEL tag ?

2条回答
倾城 Initia
2楼-- · 2019-01-24 12:13

Using XML file in Androidmanifest file :

<meta-data
 android:name="AA_MODELS"
 android:value="your.package.ModelA,your.package.ModelB,your.package.ModelC"/>
查看更多
手持菜刀,她持情操
3楼-- · 2019-01-24 12:35

You can define the models in your Application object. This disable model auto searching.

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

}

查看更多
登录 后发表回答