angthing_007
angthing_007
  • 发布:2019-08-07 21:30
  • 更新:2021-06-21 18:38
  • 阅读:1691

uniapp android插件开发时,module中的application,报空指针

分类:uni-app

public class DemoApp extends DCloudApplication {  
    private static DemoApp ins;  

    public DemoApp(){}  
    @Override  
    public void onCreate() {  
        super.onCreate();  
        ins = this;  
//      System.loadLibrary("gnustl_shared");  
        MCRSDK.init();  
        RtspClient.initLib();  
        MCRSDK.setPrint(1, null);  
        VMSNetSDK.getInstance().openLog(true);  

    }  

    public static DemoApp getIns() {  
        return ins;  
    }  
}  

在定义一个config类

private Config()   
    {  
        sp = DemoApp.getIns().getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);  
    }

此处就报错

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.HBuilder.integrate, PID: 12691
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.HBuilder.integrate/com.demo.sdk6x.v3.live.LiveActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences com.demo.sdk6x.v3.app.DemoApp.getSharedPreferences(java.lang.String, int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1620)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6701)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences com.demo.sdk6x.v3.app.DemoApp.getSharedPreferences(java.lang.String, int)' on a null object reference
at com.demo.sdk6x.v3.data.Config.<init>(Config.java:27)
at com.demo.sdk6x.v3.data.Config.getIns(Config.java:33)
at com.demo.sdk6x.v3.live.LiveActivity.initData(LiveActivity.java:243)
at com.demo.sdk6x.v3.live.LiveActivity.onCreate(LiveActivity.java:209)
at android.app.Activity.performCreate(Activity.java:7050)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2931) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1620) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:176) 
at android.app.ActivityThread.main(ActivityThread.java:6701) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783) 

2019-08-07 21:30 负责人:无 分享
已邀请:
angthing_007

angthing_007 (作者)

已经用另外的方式处理。。。

  • 以注xiao

    如何处理了呢?

    2020-02-12 11:26

狂浪泡泡

狂浪泡泡

你好,请问是怎么处理的?

该问题目前已经被锁定, 无法添加新回复