【问题标题】:Google Play Multiplayer Room not CreatingGoogle Play 多人游戏室未创建
【发布时间】:2025-12-15 14:30:01
【问题描述】:

我试图遵循 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”创建游戏助手对象,但出现以下错误:

                    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

【问题讨论】:

    标签: google-play-services google-play-games


    【解决方案1】:

    清单中缺少

    元数据 android:value="@string/app_id" android:name="com.google.android.gms.appstate.APP_ID"

    【讨论】: