Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

ClassCastException in RTCModel.java

Avatar

Level 1

Hi,

I found a problem in the RTCModel class. When I call fetchItems(room, "default_SimpleChat", "history") to obtain the chat history, the RTCModel fails with an exception:

ClassCastException: Cannot cast java.lang.Double (id=3330) to java.lang.String

The problem is located in the addItem function within the Node inner class:

    public void addItem(Map<String, Object> data)

    {

        String itemID = (String) data.get("itemID");

        if (itemID == null)

            itemID = "item";

        items.put(itemID, new Item(data));

    }

The String cast isn't checked and the itemId contains a Double 0.0.

The data returned by the service is:

[default_SimpleChat={
     nodes={
          history={
               items={
                    0.0={publisherID=EXT-MYACCOUNT-3499,
                         body={color=0.0, role=10.0, displayName=Test User, msg=test1},
                         itemID=0.0,
                         timeStamp=1.282144187104E12,
                         associatedUserID=EXT-MYACCOUNT-3499,
                         nodeName=history,
                         collectionName=default_SimpleChat},
                    1.0={publisherID=EXT-MYACCOUNT-3499,
                         body={color=0.0, role=10.0, displayName=Test User, msg=test2},
                         itemID=1.0,
                         timeStamp=1.282144188111E12,
                         associatedUserID=EXT-MYACCOUNT-3499,
                         nodeName=history,
                         collectionName=default_SimpleChat}
                    }
               }
          }
     }

To fix the problem, I changed the get to:

 String itemID = String.valueOf(data.get("itemID"));

Does that make sense?

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Employee

Thanks! We'll integrate your fix for next version.

Sent from my iPad

View solution in original post

1 Reply

Avatar

Correct answer by
Employee

Thanks! We'll integrate your fix for next version.

Sent from my iPad