英文:
onPurchasesUpdated method can't be overridden in Java for Android app
问题
我正在尝试编写一个使用应用内购买的 Android Java 应用程序。我正在使用[这个链接][1]作为指南。我已经根据“初始化结算客户端”下的说明添加了代码,但是我收到一条消息,说`onPurchasesUpdated` 方法未覆盖其超类的方法。我怀疑我漏掉了一个 `implements`,但是应该是哪一个呢?或者问题不在这里?这是我的代码:
package com.knitcards.myapplication;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
public class ShopActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shop);
}
private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
@Override
void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
}
};
}
[1]: https://developer.android.com/google/play/billing/integrate
英文:
I'm trying to write a Java for Android app using In-App Billing. I'm using this link as a guide. I've added the code they prescribe under Initialize a Billing Client, but I'm getting a message that the onPurchasesUpdated method does not override the method from its superclass. I suspect that I'm missing an implements, but which one? Or is that not the problem? Here's my code:
package com.knitcards.myapplication;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
public class ShopActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shop);
}
private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
@Override
void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
}
};
}
答案1
得分: 1
实现如下所示:
public class ShopActivity extends AppCompatActivity implements PurchasesUpdatedListener{
.
.
.
@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> purchases) {
.
.
}
}
或者您可以像[这样][1]实现。这是Google推荐的方法。还附上了[Google示例项目][2]。
[1]: https://github.com/android/play-billing-samples/blob/master/ClassyTaxiJava/app/src/main/java/com/sample/android/classytaxijava/billing/BillingClientLifecycle.java
[2]: https://github.com/android/play-billing-samples/blob/master/ClassyTaxiJava/
英文:
implement like this:-
public class ShopActivity extends AppCompatActivity implements PurchasesUpdatedListener{
.
.
.
@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> purchases) {
.
.
}
Or you can do like this. This is the recommended way by Google. Also attached is the Google Sample project
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论