2015-09-08 61 views
0

清單標籤應用:NullPointerException異常的onCreate應用糖

<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中我得到一個空指針:

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

有人艾爾雷修復它?

這裏是我的堆棧跟蹤:

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) 
+0

如果你有訪問權限,com.br.mobilecore.nucleo.CoreApplication.onCreate(CoreApplication.java:56)是什麼? –

+0

super.oncreate。 – rcorbellini

回答

0

我刪除此代碼:從我的應用程序

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

,現在所有的工作,但恐怕要回約multidex誤差修改。

+0

哈..好吧..我很困惑與上下文,這就是爲什麼我想要你添加應用程序標籤。任何我很高興的方式 –

0

在Android上的onCreate方法通常是這樣的:

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

嘗試更新onCreate方法。