How to disable scanning for model in Activeandroid
Asked Answered
H

2

7

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 ?

Harald answered 28/5, 2014 at 8:56 Comment(1)
Did you ever figure this out? I'm getting the same error!Superiority
P
13

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

}

Pelag answered 29/10, 2014 at 9:24 Comment(7)
If you encounter this problem and you already had a custom Application on your project and ActiveAndroid, you will now inherit from android.app.Application instead of com.activeandroid.app.Application.Cerography
What is the Configuration object here? I cant seem to figure out the correct import statement. Eclipse is suggesting import android.content.res.Configuration; which doesn't work.Natalianatalie
it is com.activeandroid.ConfigurationPelag
@DominikSuszczewicz I've tried the v3.0 and the v3.1 JAR of ActiveAndroid and it can't find com.activeandroid.Configuration. I'm using Android Studio. I'm extending from android.app.Application. Could you help me, please? I'd be very grateful! Thank you!Fatuitous
Thanks. @DominikSuszczewicz I also dont have the Configuration class ony get com.activeandroid.ActiveAndroid, com.activeandroid.Model and com.activeandroid.QueryUtils. Are you using the jar files from GitHub or Gradle or something else?Natalianatalie
Here is jar I use clinker.47deg.com/nexus/content/groups/public/com/michaelpardo/…Pelag
@DominikSuszczewicz Thanks this works, the jars on ActiveAndroid GitHub are not the latest.Natalianatalie
H
5

Using XML file in Androidmanifest file :

<meta-data
 android:name="AA_MODELS"
 android:value="your.package.ModelA,your.package.ModelB,your.package.ModelC"/>
Harald answered 29/10, 2014 at 9:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.