Ionic 应用程序崩溃与致命例外:java.lang.RuntimeException:无法启动活动

n3h0vuf2  于 2023-08-01  发布在  Ionic
关注(0)|答案(2)|浏览(162)

我有一个离子,Angular 和电容器的应用程序。我最近更新了它到最新版本的Ionic 7,Angular 16和Capacitor5。更新后,在Android上当我第一次安装它时,它工作正常,没有任何问题。但当我重新启动应用程序时,它崩溃了,以下例外。

FATAL EXCEPTION: main   
Process: App Id, PID: 26600
java.lang.RuntimeException: Unable to start activity 
ComponentInfo{APPID/APPID.MainActivity}: java.lang.NullPointerException: Attempt to 
invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null 
object reference at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3540)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3700)
at 
android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:236)at android.app.ActivityThread.main(ActivityThread.java:8061) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967) 
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference at com.getcapacitor.Bridge.isNewBinary(Bridge.java:381) at com.getcapacitor.Bridge.loadWebView(Bridge.java:255) 
at com.getcapacitor.Bridge.<init>(Bridge.java:215) 
at com.getcapacitor.Bridge.<init>(Unknown Source:0)
at com.getcapacitor.Bridge$Builder.create(Bridge.java:1513) 
at com.getcapacitor.BridgeActivity.load(BridgeActivity.java:42)
at com.getcapacitor.BridgeActivity.onCreate(BridgeActivity.java:36)
at android.app.Activity.performCreate(Activity.java:8127) 
at android.app.Activity.performCreate(Activity.java:8098)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3513)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3700) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:236) 
at android.app.ActivityThread.main(ActivityThread.java:8061) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967) 

字符串

项目信息:

Ionic CLI                     : 7.1.1 
Ionic Framework               : @ionic/angular 7.0.14
@angular-devkit/build-angular : 16.1.0
@angular-devkit/schematics    : 16.1.0
@angular/cli                  : 16.1.0
@ionic/angular-toolkit        : 9.0.0

Capacitor:

Capacitor CLI      : 5.1.0
@capacitor/android : 5.1.0
@capacitor/core    : 5.1.0
@capacitor/ios     : 5.1.0
NodeJS : v18.10.0 
npm    : 8.19.2


Android Studio Flamingo | 2022.2.1 Patch 2
Java 17
Gradle 8.0.0


有什么建议可以是什么问题,我如何解决它?

nxowjjhe

nxowjjhe1#

您遇到的错误是Android电容器端的空指针。
查看Bridge.java:381,似乎缺少versionCode或versionName。

private boolean isNewBinary() {
        String versionCode = "";
        String versionName = "";
        SharedPreferences prefs = getContext()
            .getSharedPreferences(com.getcapacitor.plugin.WebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
        String lastVersionCode = prefs.getString(LAST_BINARY_VERSION_CODE, null);
        String lastVersionName = prefs.getString(LAST_BINARY_VERSION_NAME, null);

        [...]

        // Here it breaks!
        if (!versionCode.equals(lastVersionCode) || !versionName.equals(lastVersionName)) {
   
        [...]
}

字符串
Bridge.java
所以要解决这个问题,检查是否在你的android项目设置中设置了versionCode和versionName。
(File->项目结构->模块->默认配置)

e5nqia27

e5nqia272#

这似乎是一个非常常见的“空点异常”问题。比如说...

var value: String = "aa"
var nullStr: String = null
if( nullStr.equals(value) ) // <-- maybe this line like or
if( nullStr == value ) // <-- also be expressed like this.

字符串
'com.getcapacitor.Bridge.java'文件在1513行分析。答案就在你写的日志里。

相关问题