我正在尝试将Real-Time Multiplayer应用到我的Android应用中。但它崩溃了以下错误:
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object com.google.android.gms.games.multiplayer.realtime.Room.freeze()' on a null object reference`
Google Play给出了以下错误:错误代码6,NETWORK_ERROR_OPERATION_FAILED
中对Android文档中此错误的描述没有帮助尝试执行需要网络访问的操作时发生网络错误。
这些是我的代码的一些部分:
private RoomConfig.Builder makeBasicRoomConfigBuilder() {
return RoomConfig.builder(updateListener)
.setMessageReceivedListener(realTimeMessageReceivedListener)
.setRoomStatusUpdateListener(roomStatusUpdateListener);
}
private void startQuickGame() {
// auto-match criteria to invite one random automatch opponent.
// You can also specify more opponents (up to 3).
Bundle am = RoomConfig.createAutoMatchCriteria(1, 1, 0);
// build the room config:
RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
roomConfigBuilder.setAutoMatchCriteria(am);
RoomConfig roomConfig = roomConfigBuilder.build();
// create room:
Games.RealTimeMultiplayer.create(mGoogleApiClient, roomConfig);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// TODO:go to game screen
}
导致此次崩溃的原因是什么?如何解决?
编辑:创建房间时,错误发生在开头。无论是快速游戏还是挑选对手都无关紧要