我正在努力添加应用内结算并在this official documentation
工作我在Binding to IInAppBillingService
这是我的代码:
public class CommunityActivity extends BaseActivity implements ServiceConnection
{
ArrayAdapter<ChatMessage> adapter;
Dialog dialog;
ArrayList<ChatMessage> chat = new ArrayList <ChatMessage>( );
IInAppBillingService mService;
ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name,
IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
FlurryAgent.onStartSession(this, "8CA5LTZ5M73EG8R35SXG");
setContentView(R.layout.community);
bindService(new
Intent("com.android.vending.billing.InAppBillingService.BIND"),
mServiceConn, Context.BIND_AUTO_CREATE);
但是我得到编译错误,说我必须实现onServiceConnected和onServiceDisconnected方法。但我认为我已经按照示例建议的方式添加了它们。
我在哪里出错?谢谢!
答案 0 :(得分:1)
错误是因为您已按以下方式声明了您的课程
public class CommunityActivity extends BaseActivity implements ServiceConnection
现在编译器希望你在onServiceConnected
中实现这两个函数on ServiceDisconnected
和CommunityActivity
。但是在这堂课上找不到它们。
删除此implements ServiceConnection
并且代码应该成功编译。