我对 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/