我对 Google Play结算库 v3有例外。 我在 onDestroy 活动方法中发布了结算客户端。
有人有这个问题吗?
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
at com.android.billingclient.api.BillingClientImpl$BillingServiceConnection.onServiceConnected(BillingClientImpl.java:668)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1259)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1276)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:5830)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:879)
结算客户端连接呼叫代码:
private com.android.billingclient.api.BillingClient billingClient;
public AppBillingManager(Context context) {
billingClient = new BillingClient.Builder(context)
.setListener(this)
.build();
}
public void doConnect(final Runnable postConnection) {
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(int resultCode) {
isConnected = BillingClient.BillingResponse.OK == resultCode;
notifyConnectivityState();
if (isConnected) {
postConnection.run();
} else {
listener.onConnectedToBillingService(resultCode);
}
}
@Override
public void onBillingServiceDisconnected() {
isConnected = false;
listener.onDisconnectedBillingService();
}
});
}
public void release() {
this.billingClient.endConnection();
}
答案 0 :(得分:0)