gpt4 book ai didi

java - IabHelper(类)Dispose(方法)未处理的异常

转载 作者:搜寻专家 更新时间:2023-11-01 08:27:46 25 4
gpt4 key购买 nike

我正在尝试在我最新的 android 项目中实现应用内购买。为此,我正在关注此 guide .一切都很顺利,直到我使用 dispose 方法关闭与 Play 商店的所有通信。我得到的是以下错误:

Error:(101, 45) error: unreported exception IabAsyncInProgressException; must be caught or declared to be thrown

在下面的代码段中:

@Override
public void onDestroy() {
super.onDestroy();
//Always unbind the with the store connection, otherwise performance degradation of the device may follow.
if (mHelper != null) mHelper.dispose();
mHelper = null;
}

深入了解 IabHelper 类 (Java) 后,我找到了 dispose 方法。方法代码如下:

    /**
* Dispose of object, releasing resources. It's very important to call this
* method when you are done with this object. It will release any resources
* used by it such as service connections. Naturally, once the object is
* disposed of, it can't be used again.
*/
public void dispose() throws IabAsyncInProgressException {
synchronized (mAsyncInProgressLock) {
if (mAsyncInProgress) {
throw new IabAsyncInProgressException("Can't dispose because an async operation " +
"(" + mAsyncOperation + ") is in progress.");
}
}
logDebug("Disposing.");
mSetupDone = false;
if (mServiceConn != null) {
logDebug("Unbinding from service.");
if (mContext != null) mContext.unbindService(mServiceConn);
}
mDisposed = true;
mContext = null;
mServiceConn = null;
mService = null;
mPurchaseListener = null;
}

我应该怎么做才能解决这个错误?我知道我应该捕获和异常,但是我没有足够的信心在这个类中自己更改这个方法。

(感谢您的帮助)

最佳答案

经过更多研究后,我发现这个问题已经被提出并得到了回答。不幸的是,该问题仍被标记为未回答。这里有 link to the original question .

解决方法很简单:

  1. 您可以从指南中获得的文件已过时,应改为从 github 下载.
  2. onDestroy 方法中,您应该改用以下代码:

    @Override
    public void onDestroy() {
    super.onDestroy();
    //Always unbind the connection with the store, otherwise performance degradation of the device may follow.
    if (mHelper != null) {
    mHelper.disposeWhenFinished();
    mHelper = null;
    }
    }

disposeWhenFinished 这是一个比 dispose 更优雅的解决方案。

关于java - IabHelper(类)Dispose(方法)未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43180273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com