Android billing v3 - BillingClientImpl.java:668中的NullPointerException

时间:2017-08-15 11:01:57

标签: android in-app-billing android-billing

我对 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();
}

1 个答案:

答案 0 :(得分:0)

谷歌最近发布了新版计费库。看看这个。这应该是固定的。 https://android-developers.googleblog.com/2017/09/google-play-billing-library-10-released.html