NullPointerException onCreate应用程序与糖

时间:2015-09-08 20:19:16

标签: android sugarorm

清单标记应用程序:

   <application
        android:name=".util.StartApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_guard"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        tools:replace="android:name">

我的应用程序扩展了糖应用程序

 StartApplication extends CoreApplication{...} //it is in a main module
 CoreApplication extends com.orm.SugarApp{...} //it is in a library module

在oncreate上我得到一个nullpointer:

public void onCreate() {
        super.onCreate();
有人在修理它吗?

这是我的stacktrace:

java.lang.RuntimeException: Unable to create application br.com.egsys.guardronda.util.StartApplication: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4641)
            at android.app.ActivityThread.access$1500(ActivityThread.java:155)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5343)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.PackageManager android.content.Context.getPackageManager()' on a null object reference
            at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:91)
            at com.orm.SugarConfig.getMetaDataString(SugarConfig.java:74)
            at com.orm.SugarConfig.getDatabaseName(SugarConfig.java:19)
            at com.orm.SugarDb.<init>(SugarDb.java:27)
            at com.orm.Database.<init>(Database.java:12)
            at com.orm.SugarApp.onCreate(SugarApp.java:11)
            at com.br.mobilecore.nucleo.CoreApplication.onCreate(CoreApplication.java:56)
            at br.com.egsys.guardronda.util.StartApplication.onCreate(StartApplication.java:71)

2 个答案:

答案 0 :(得分:0)

我删除此代码:

@Override
    protected void attachBaseContext(Context base) {
        MultiDex.install(this);
    }

从我的应用程序,现在一切正常,但我害怕得到关于multidex的错误。

答案 1 :(得分:0)

Android中的onCreate方法通常如下所示:

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    //Everything else
}

尝试更新onCreate方法。