Android 计费 v3 - BillingClientImpl.java 中的 NullPointerException :668

标签 android in-app-billing android-billing

我对 Google Play Billing Library v3 有异议。 我在 onDestroy Activity 方法中释放计费客户端。

有人遇到过这个问题吗?

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

最佳答案

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

关于Android 计费 v3 - BillingClientImpl.java 中的 NullPointerException :668,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45691533/

相关文章:

Android:垂直RatingBar?

java - 无法从 Google 的 IAB 框架捕获 IllegalStateException

android - 应用程序计费 v3 中的开发人员错误 android

安卓工作室 : debug classes depending on a flavour

Android Billing 4.0.0 - 无购买结果 querySkuDetailsAsync()

Android InApp 购买错误代码 102

android - 使用 OpenGL ES 1.0 在 Android 上进行离屏渲染的选项?

android - 调用setTextColor后,TextView中没有出现文字

Android Compose-Navigation 2.4.0-alpha2 崩溃并出现 NoSuchMethodError

安卓应用内支付SDK V3 : Error refreshing inventory