我试图按照ButtonClicker示例。我的主要活动扩展了AndroidApplication,因为我正在使用libgdx,但我似乎无法创建房间。我调用“Games.RealTimeMultiplayer.create(getApiClient(),roomBuilder.build())”后,代码停止了。
我认为我的问题出在getApiClient()的某个地方 愿意帮助理解我做错了什么
参见代码:
在我的OnCreate()
中 mHelper = new GameHelper(this, 2);
当我使用2以外的其他任何东西作为第二个参数时,游戏甚至不会加载
protected GoogleApiClient getApiClient() {
Log.d(TAG, "getApiClient() " + mHelper.getApiClient());
return mHelper.getApiClient();
}
致电快速游戏
private void startQuickGame(){
Log.d(TAG, "StartQuickGame()");
//1st param is Minimum players, 2nd param is maximum and 3rd is exclusivebitmask???
Bundle am = RoomConfig.createAutoMatchCriteria(1, 4, 0);
RoomConfig.Builder roomBuilder = RoomConfig.builder(this);
roomBuilder.setMessageReceivedListener(this);
roomBuilder.setRoomStatusUpdateListener(this);
roomBuilder.setAutoMatchCriteria(am);
Games.RealTimeMultiplayer.create(getApiClient(), roomBuilder.build());
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Log.d(TAG, " startQuickGame()" + "createRoom called");
}
我尝试使用“GameHelper.CLIENT_ALL”创建Game Helper对象,我收到以下错误:
03-11 09:34:24.083: E/MoreInfoHPW_ViewGroup(15954): Parent view is not a TextView
03-11 09:34:24.083: D/Launcher(1234): onTrimMemory. Level: 20
03-11 09:34:24.083: D/STATUSBAR-IconMerger(950): checkOverflow(1368), More:false, Req:false Child:6
03-11 09:34:24.103: W/PopupManager(15954): You have not specified a View to use as content view for popups. Falling back to the Activity content view which may not work properly in future versions of the API. Use setViewForPopups() to set your content view.
03-11 09:34:24.103: D/AndroidRuntime(15954): Shutting down VM
03-11 09:34:24.103: W/dalvikvm(15954): threadid=1: thread exiting with uncaught exception (group=0x41b13898)
03-11 09:34:24.103: E/AndroidRuntime(15954): FATAL EXCEPTION: main
03-11 09:34:24.103: E/AndroidRuntime(15954): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crazyEagle/com.crazyEagle.MainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.ActivityThread.access$700(ActivityThread.java:159)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.os.Handler.dispatchMessage(Handler.java:99)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.os.Looper.loop(Looper.java:137)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.ActivityThread.main(ActivityThread.java:5419)
03-11 09:34:24.103: E/AndroidRuntime(15954): at java.lang.reflect.Method.invokeNative(Native Method)
03-11 09:34:24.103: E/AndroidRuntime(15954): at java.lang.reflect.Method.invoke(Method.java:525)
03-11 09:34:24.103: E/AndroidRuntime(15954): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
03-11 09:34:24.103: E/AndroidRuntime(15954): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
03-11 09:34:24.103: E/AndroidRuntime(15954): at dalvik.system.NativeStart.main(Native Method)
03-11 09:34:24.103: E/AndroidRuntime(15954): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
03-11 09:34:24.103: E/AndroidRuntime(15954): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:320)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.Activity.requestWindowFeature(Activity.java:3338)
03-11 09:34:24.103: E/AndroidRuntime(15954): at com.crazyEagle.MainActivity.onCreate(MainActivity.java:150)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.Activity.performCreate(Activity.java:5372)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
03-11 09:34:24.103: E/AndroidRuntime(15954): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
03-11 09:34:24.103: E/AndroidRuntime(15954): ... 11 more
答案 0 :(得分:0)
清单中缺少
元数据android:value =“@ string / app_id”android:name =“com.google.android.gms.appstate.APP_ID”