嗨朋友,我正在尝试玩游戏服务示例,即“buttonclicker”,我想做的是,通过邀请 buttonclick 将当前时间发送给其他参与者,在这个例子中 startActivityForResult(intent,requestcode) 和另一个带有 3 个参数 startActivityForResult(intent ,requestcode,bundle),在这里我遇到了问题;
case1:我已经尝试了带有 3 个参数的第二种方法,其中包含我当前的时间,但是当我运行该示例时,它通过错误
它的代码:
@Override
public void onClick(View v)
{
Intent intent;
Bundle BundleTimer = new Bundle();
BundleTimer.putString("StartTime",millisecond);
switch (v.getId()) {
case R.id.button_single_player:
case R.id.button_single_player_2:
resetGameVars();
startGame(false);
break;
case R.id.button_sign_in:
// user wants to sign in
if (!verifyPlaceholderIdsReplaced())
{
showAlert("Error", "Sample not set up correctly. Please see README.");
return;
}
beginUserInitiatedSignIn();
break;
case R.id.button_sign_out:
signOut();
switchToScreen(R.id.screen_sign_in);
break;
case R.id.button_invite_players:
// show list of invitable players
intent = getGamesClient().getSelectPlayersIntent(1, 3);
switchToScreen(R.id.screen_wait);
startActivityForResult(intent, RC_SELECT_PLAYERS, BundleTimer);
break;
case R.id.button_see_invitations:
// show list of pending invitations
intent = getGamesClient().getInvitationInboxIntent();
switchToScreen(R.id.screen_wait);
startActivityForResult(intent, RC_INVITATION_INBOX, BundleTimer);
break;
case R.id.button_accept_popup_invitation:
// user wants to accept the invitation shown on the invitation
// popup
// (the one we got through the OnInvitationReceivedListener).
acceptInviteToRoom(mIncomingInvitationId);
mIncomingInvitationId = null;
break;
}
}
案例1的logcat:
> 08-30 19:26:28.687: E/AndroidRuntime(13846): FATAL EXCEPTION: main
> 08-30 19:26:28.687: E/AndroidRuntime(13846):
> java.lang.NoSuchMethodError:
> com.example1.playservicedemo1.multiplayer.startActivityForResult 08-30
> 19:26:28.687: E/AndroidRuntime(13846): at
> com.example1.playservicedemo1.multiplayer.onClick(multiplayer.java:215)
> 08-30 19:26:28.687: E/AndroidRuntime(13846): at
> android.view.View.performClick(View.java:2485) 08-30 19:26:28.687:
> E/AndroidRuntime(13846): at
> android.view.View$PerformClick.run(View.java:9080) 08-30 19:26:28.687:
> E/AndroidRuntime(13846): at
> android.os.Handler.handleCallback(Handler.java:587) 08-30
> 19:26:28.687: E/AndroidRuntime(13846): at
> android.os.Handler.dispatchMessage(Handler.java:92) 08-30
> 19:26:28.687: E/AndroidRuntime(13846): at
> android.os.Looper.loop(Looper.java:130) 08-30 19:26:28.687:
> E/AndroidRuntime(13846): at
> android.app.ActivityThread.main(ActivityThread.java:3687) 08-30
> 19:26:28.687: E/AndroidRuntime(13846): at
> java.lang.reflect.Method.invokeNative(Native Method) 08-30
> 19:26:28.687: E/AndroidRuntime(13846): at
> java.lang.reflect.Method.invoke(Method.java:507) 08-30 19:26:28.687:
> E/AndroidRuntime(13846): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
> 08-30 19:26:28.687: E/AndroidRuntime(13846): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 08-30
> 19:26:28.687: E/AndroidRuntime(13846): at
> dalvik.system.NativeStart.main(Native Method)
case2:在这里我尝试使用 intent.putextra("statrtime",millisecond) 发送有意图的数据,但是当我尝试在运行相同示例代码的其他应用程序中检索此额外值时,它通过来自意图的 getextra 上的 nullpointer;
它的代码
@Override
public void onClick(View v)
{
Intent intent;
switch (v.getId()) {
case R.id.button_single_player:
case R.id.button_single_player_2:
resetGameVars();
startGame(false);
break;
case R.id.button_sign_in:
// user wants to sign in
if (!verifyPlaceholderIdsReplaced())
{
showAlert("Error", "Sample not set up correctly. Please see README.");
return;
}
beginUserInitiatedSignIn();
break;
case R.id.button_sign_out:
signOut();
switchToScreen(R.id.screen_sign_in);
break;
case R.id.button_invite_players:
// show list of invitable players
intent = getGamesClient().getSelectPlayersIntent(1, 3);
intent.putExtra("StartTime", millisecond);
switchToScreen(R.id.screen_wait);
startActivityForResult(intent, RC_SELECT_PLAYERS);
break;
case R.id.button_see_invitations:
// show list of pending invitations
intent = getGamesClient().getInvitationInboxIntent();
intent.putExtra("StartTime", millisecond);
switchToScreen(R.id.screen_wait);
startActivityForResult(intent, RC_INVITATION_INBOX);
break;
case R.id.button_accept_popup_invitation:
// user wants to accept the invitation shown on the invitation
// popup
// (the one we got through the OnInvitationReceivedListener).
acceptInviteToRoom(mIncomingInvitationId);
mIncomingInvitationId = null;
break;
}
}
案例2的logcat:
> 08-30 19:01:46.264: E/AndroidRuntime(25770):
> java.lang.NullPointerException: println needs a message 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> android.util.Log.println_native(Native Method) 08-30 19:01:46.264:
> E/AndroidRuntime(25770): at android.util.Log.i(Log.java:159) 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> com.example1.playservicedemo1.multiplayer.onInvitationReceived(multiplayer.java:573)
> 08-30 19:01:46.264: E/AndroidRuntime(25770): at
> com.google.android.gms.internal.bj$n.a(Unknown Source) 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> com.google.android.gms.internal.bj$n.a(Unknown Source) 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> com.google.android.gms.internal.p$b.p(Unknown Source) 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> com.google.android.gms.internal.p$a.handleMessage(Unknown Source)
> 08-30 19:01:46.264: E/AndroidRuntime(25770): at
> android.os.Handler.dispatchMessage(Handler.java:99) 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> android.os.Looper.loop(Looper.java:137) 08-30 19:01:46.264:
> E/AndroidRuntime(25770): at
> android.app.ActivityThread.main(ActivityThread.java:5103) 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> java.lang.reflect.Method.invokeNative(Native Method) 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> java.lang.reflect.Method.invoke(Method.java:525) 08-30 19:01:46.264:
> E/AndroidRuntime(25770): at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
> 08-30 19:01:46.264: E/AndroidRuntime(25770): at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 08-30
> 19:01:46.264: E/AndroidRuntime(25770): at
> dalvik.system.NativeStart.main(Native Method)
在此示例中,我想将持续时间发送给选定的玩家,以便如果他们在该时间之后没有响应,则他们不会为该请求而玩,如果他们在该时间段内响应,则允许他们玩游戏,
朋友我被困在这个问题上,请建议如何完成这个,抱歉英语不好,谢谢