Jade Jade - 5 months ago 21
Java Question

Class not found, unmarshalling error when trying to make a multiplayer game with play store

So I'm trying to make a multiplayer game with friends. For the multiplayer part, I connected the project to the developer console and copied some sample code provided by Google, the classic button clicker, to see how the coding works. The problem is, when I run it and send an invite to someone, it doesn't work. The invite shows up on the other device but when it accepts it, the project only works on one phone and stops working on the other. I am using actual devices, not emulators. This is the log cat.

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=10002, result=-1, data=Intent { (has extras) }} to activity {ml.digits/ml.digits.MultiPlayerSignIn}: java.lang.IllegalStateException: Room ID must not be null or empty
at android.app.ActivityThread.deliverResults(ActivityThread.java:4058)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4101)
at android.app.ActivityThread.access$1400(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1497)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.IllegalStateException: Room ID must not be null or empty
at android.os.Parcel.readException(Parcel.java:1548)
at android.os.Parcel.readException(Parcel.java:1493)
at com.google.android.gms.games.internal.IGamesService$Stub$Proxy.zzb(Unknown Source)
at com.google.android.gms.games.internal.GamesClientImpl.zza(Unknown Source)
at com.google.android.gms.games.internal.api.RealTimeMultiplayerImpl.sendUnreliableMessage(Unknown Source)
at ml.digits.MultiPlayerSignIn.broadcastScore(MultiPlayerSignIn.java:760)
at ml.digits.MultiPlayerSignIn.startGame(MultiPlayerSignIn.java:638)
at ml.digits.MultiPlayerSignIn.onActivityResult(MultiPlayerSignIn.java:229)
at android.app.Activity.dispatchActivityResult(Activity.java:6549)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4054)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4101)
at android.app.ActivityThread.access$1400(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1497)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:145)
  at android.app.ActivityThread.main(ActivityThread.java:5942)
   at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)


Oddly enough, when I try to send the invite from the other device, it connects the two devices and the game starts. In the game, you should be able to see your score and the other players score, However, you can only see both scores on one device and in the other, you can only see your own score. Here's the logcat for that.

E/Parcel﹕ Class not found when unmarshalling: com.google.android.gms.games.multiplayer.realtime.RoomEntity
java.lang.ClassNotFoundException: com.google.android.gms.games.multiplayer.realtime.RoomEntity
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at java.lang.Class.forName(Class.java:272)
at android.os.Parcel.readParcelableCreator(Parcel.java:2275)
at android.os.Parcel.readParcelable(Parcel.java:2239)
at android.os.Parcel.readValue(Parcel.java:2146)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.BaseBundle.getString(BaseBundle.java:918)
at android.content.Intent.getStringExtra(Intent.java:5386)
at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1811)
at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1364)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4727)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:4572)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3093)
at android.os.Binder.execTransact(Binder.java:446)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.games.multiplayer.realtime.RoomEntity" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
 at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:308)
at java.lang.Class.forName(Class.java:272)
at android.os.Parcel.readParcelableCreator(Parcel.java:2275)
at android.os.Parcel.readParcelable(Parcel.java:2239)
at android.os.Parcel.readValue(Parcel.java:2146)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)
at android.os.BaseBundle.unparcel(BaseBundle.java:221)
at android.os.BaseBundle.getString(BaseBundle.java:918)
at android.content.Intent.getStringExtra(Intent.java:5386)
at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1811)
at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1364)
at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4727)
at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:4572)
at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140)
at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3093)
at android.os.Binder.execTransact(Binder.java:446)
Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.games.multiplayer.realtime.RoomEntity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 18 more


Last but not least, here's the code for the method in the MultiPlayerSignIn.class that throws the error.

if (finalScore) {
Log.d(TAG, "This is the room"+mRoomId);
// final score notification must be sent via reliable message
Games.RealTimeMultiplayer.sendReliableMessage(mGoogleApiClient, null, mMsgBuf,
mRoomId, p.getParticipantId());

} else {
// it's an interim score notification, so we can use unreliable
Games.RealTimeMultiplayer.sendUnreliableMessage(mGoogleApiClient, mMsgBuf, mRoomId,
p.getParticipantId());
}


Here's where the room is being created. It's null when it shouldnt be

// Accept the given invitation.
void acceptInviteToRoom(String invId) {
// accept the invitation
Log.d(TAG, "Accepting invitation: " + invId);
RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this);
roomConfigBuilder.setInvitationIdToAccept(invId)
.setMessageReceivedListener(this)
.setRoomStatusUpdateListener(this);
switchToScreen(R.id.screen_wait);
keepScreenOn();
resetGameVars();
Games.RealTimeMultiplayer.join(mGoogleApiClient, roomConfigBuilder.build());
}


Thanks for any help (: Here's where I got the code from.

Answer Source

Try to insert mRoomId = room.getRoomId() in the onJoinedRoom-Method:

public void onJoinedRoom(int statusCode, Room room) {

    ...

    mRoomId = room.getRoomId();

    ...
}