我正在嘗試修復一個導致我發布到 Google Play 商店的應用程式崩潰的錯誤。
來自 Google Play 控制臺的崩潰堆疊跟蹤:
java.lang.NullPointerException:
at com.myApp.Advertising.InterstitialAdsRunCallback.setViewed (InterstitialAdsRunCallback.java:11)
at com.myApp.AndroidLauncher$2.onInterstitialAdClosed (AndroidLauncher.java:65)
at com.ironsource.mediationsdk.A$4.run (A.java:7)
at android.os.Handler.handleCallback (Handler.java:938)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:223)
at android.app.ActivityThread.main (ActivityThread.java:7888)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:981)
setViewed 函式的代碼是:
package com.myApp.Advertising;
public abstract class InterstitialAdsRunCallback implements Runnable {
boolean viewed;
public boolean viewedAd() {
return viewed;
}
public void setViewed(boolean viewed) {
this.viewed = viewed; // line 11
}
}
以及呼叫 setViewed 的代碼:
public void onInterstitialAdClosed() {
InterstitialAdsRunCallback adRunnable = showInterstitialAdRunnable.getAdRunnable();
adRunnable.setViewed(true); // line 65
adRunnable.run();
IronSource.loadInterstitial();
}
從 .aab 反編譯的 InterstitialAdsRunCallback 類:
.class public abstract Lcom/myApp/Advertising/InterstitialAdsRunCallback;
.super Ljava/lang/Object;
.source "InterstitialAdsRunCallback.java"
# interfaces
.implements Ljava/lang/Runnable;
# instance fields
.field public viewed:Z
# direct methods
.method public constructor <init>()V
.registers 1
.line 3
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
return-void
.end method
那么,原始布爾屬性如何導致 NullPointerException?我可能還缺少其他東西。
uj5u.com熱心網友回復:
R8、ProGuard 等類似的優化工具通常是行內訪問器方法,但行號資訊仍然指向原始來源。
如果adRunnable是 null 并且setViewed()訪問器是行內的,你會得到一個像這樣的 NPE。
uj5u.com熱心網友回復:
我認為您不能使用該函式,因為setViewed()物件adRunnable為 null 而不是因為原始布爾屬性...
java.lang.NullPointerException:
at com.myApp.Advertising.InterstitialAdsRunCallback.setViewed
檢查函式的回傳showInterstitialAdRunnable.getAdRunnable();是否為空?
uj5u.com熱心網友回復:
你不能直接實體化抽象類,可能是因為這個原因你得到了 NullPointerException。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/490471.html
上一篇:解決:Failed to download metadata for repo ‘base‘
下一篇:哪個組件指定活動的入口點?
