Android 有时环信初始化失败,创建applocation失败

  java.lang.RuntimeException: Unable to create application com.wlkj.ciyun.sj.config.MyApp: java.lang.NullPointerException
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4349)
        at android.app.ActivityThread.access$1500(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5019)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
        at com.hyphenate.chat.a.b.a(Unknown Source)
        at com.hyphenate.chat.a.b.a(Unknown Source)
        at com.hyphenate.chat.EMClient.init(Unknown Source)
        at com.hyphenate.easeui.EaseUI.init(EaseUI.java:118)
        at com.wlkj.ciyun.sj.config.MyApp.onCreate(MyApp.java:50)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4346)

Android 有时环信初始化失败,创建applocation失败_第1张图片

实际上这个问题是因为Android工程方法数量超过了65536的限制
  下面给出解决方法:   
  第一步:
    在gradle的配置文件中添加依赖 compile 'com.android.support:multidex:1.0.1'
  第二步:
    添加 multiDexEnabled true
    android {
      ...
      defaultConfig {
         ...
         multiDexEnabled true
         ...
       }
     }
  第三步:
    在工程的MainApplication中重写  attachBaseContext() 方法
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
也可以直接在Application的onCreate方法中super.OnCreate();方法前加一句话MultiDex.install(this)就可以了

你可能感兴趣的:(错误)