Java 如何解决此错误
我在两个文件的264和163上有一个错误,但在编辑器中看起来很好 第264行:Java 如何解决此错误,java,android,Java,Android,我在两个文件的264和163上有一个错误,但在编辑器中看起来很好 第264行: if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) { 第163行: mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { 我找不到为什么我的活动无法开始 日志: 这是包含第163行的整个支付块: //=============
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
第163行:
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
我找不到为什么我的活动无法开始
日志:
这是包含第163行的整个支付块:
//=====================================================
String base64EncodedPublicKey = "MIHNMA0GCSqGSIb3DQEBAQUAA4G7ADCBtwKBrwDtUWVdLt6clZldCQGZxcyyWeeBp8vF/6qm7qCKuQPdXg6HB71hVu8lmcEO0VcyS2xpzXt03iW7LhKXRtDsxi5H9wHLESfY9SQUc0ugPD+n5nE+I6zCiB/RB2WscvZFa3JCiYRbmsvez+DwaQSHfq6CNUawl0fbz4NfJntZHKYHanm6PtjquO9JSj+Pa9PV38C3o5Y3ALCvPMCAwEAAQ==";
mHelper = new IabHelper(this, base64EncodedPublicKey);
mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
Log.d(TAG, "Query inventory finished.");
if (result.isFailure()) {
Log.d(TAG, "Failed to query inventory: " + result);
return;
}
else {
Log.d(TAG, "Query inventory was successful.");
// does the user have the premium upgrade?
mIsPremium = inventory.hasPurchase(SKU_PREMIUM);
if (mIsPremium){
MasrafSeke(inventory.getPurchase(SKU_PREMIUM));
}
// update UI accordingly
Log.d(TAG, "User is " + (mIsPremium ? "PREMIUM" : "NOT PREMIUM"));
}
Log.d(TAG, "Initial inventory query finished; enabling main UI.");
}
};
mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
return;
}
else if (purchase.getSku().equals(SKU_PREMIUM)) {
// give user access to premium content and update the UI
Toast.makeText(AndroidHTMLActivity.this,"خرید موفق",Toast.LENGTH_SHORT).show();
MasrafSeke(purchase);
}
}
};
Log.d(TAG, "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
Log.d(TAG, "Setup finished.");
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.d(TAG, "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
mHelper.queryInventoryAsync(mGotInventoryListener);
}
});
似乎是个问题。方法
querytentservices
返回一个null
,而不是一个空列表
尝试从以下位置更新代码:
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
// service available to handle that Intent
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
}
else {
// no service available to handle that Intent
if (listener != null) {
listener.onIabSetupFinished(
new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device."));
}
}
为此:
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
List<ResolveInfo> intentServices = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
if (intentServices != null && intentServices.isEmpty() == false) {
// service available to handle that Intent
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
}
else {
// no service available to handle that Intent
if (listener != null) {
listener.onIabSetupFinished(
new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device."));
}
}
Intent-serviceentent=newintent(“com.android.vending.billing.InAppBillingService.BIND”);
List intentServices=mContext.getPackageManager().queryIntentServices(serviceIntent,0);
if(intentServices!=null&&intentServices.isEmpty()==false){
//可用于处理该意图的服务
bindService(serviceentent、mServiceConn、Context.BIND\u AUTO\u CREATE);
}
否则{
//没有可用于处理该意图的服务
if(侦听器!=null){
listener.onIabSetupFinished(
新结果(计费\响应\结果\计费\不可用,
“设备上的计费服务不可用。”);
}
}
您得到了一个空指针……因此有些东西没有初始化。你能再发一些代码吗…可以是McContext吗?先发几行163@petey:163之前:Log.d(标记“启动设置”)代码>请将更多代码发布到question@petey:检查它。请使用:java.lang.IllegalStateException:未设置IAB帮助程序。IabHelper.java:798 IabHelper.java:626 IabHelper.java:655 AndroidHTMLActivity.java:139 IabHelper.java:290 AndroidHTMLActivity.java:130仅更改答案中的行无法接收此异常。检查您是否做了其他更改。@Amir.KH:这是另一个问题。对于NullPointerException,Mattia是正确的。您应该为IllegalStateException创建另一个问题。一个答案不能解决所有问题
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
List<ResolveInfo> intentServices = mContext.getPackageManager().queryIntentServices(serviceIntent, 0);
if (intentServices != null && intentServices.isEmpty() == false) {
// service available to handle that Intent
mContext.bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
}
else {
// no service available to handle that Intent
if (listener != null) {
listener.onIabSetupFinished(
new IabResult(BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE,
"Billing service unavailable on device."));
}
}