ActivityRecord库类扩展模型NullPointerException

时间:2015-01-22 00:16:47

标签: android

我正在使用Android的ActivityRecord(ORM库)。每当使用扩展模型时。我总是得到NullPointerException。有什么解决方案吗?我的错误在哪里?代码示例如下。非常感谢您的帮助。

01-22 02:08:11.883    7238-7238/main.yurtrehberi.yourmovies E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{main.yurtrehberi.yourmovies/main.yurtrehberi.yourmovies.Ui.MainActivity}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
        at android.app.ActivityThread.access$700(ActivityThread.java:140)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4921)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.NullPointerException
        at com.activeandroid.Cache.getTableInfo(Cache.java:148)
        at com.activeandroid.Model.<init>(Model.java:54)
        at main.yurtrehberi.yourmovies.Database.Model.Movie.<init>(Movie.java:11)
        at main.yurtrehberi.yourmovies.Ui.MainActivity.onCreate(MainActivity.java:44)
        at android.app.Activity.performCreate(Activity.java:5206)

MainActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Model model = new Movie();
}

电影课程:

@Table(name = "Movies")
public class Movie extends Model {

    private String name;

    public void setName(String name) {
        this.name = name;
    }
}

1 个答案:

答案 0 :(得分:0)

“另请注意,应用程序名称指向ActiveAndroid应用程序类。此步骤是ActiveAndroid工作所必需的。。如果您已经指向自定义Application类,只需将该类作为子类com.activeandroid.app.Application“。

<manifest ...>
    <application android:name="com.activeandroid.app.Application" ...>
    ...
    </application>
</manifest>

此外,您还需要将com.android.support:support-v4库添加到项目的依赖项中。