« Return to Thread: Shared Object editing

Re: Shared Object editing

by javaguy :: Rate this Message:

Reply to Author | View in Thread

Cristian Rusu schrieb:

> On Thu, Jul 9, 2009 at 14:23, javaguy <javaguy@...> wrote:
>
>> Hi Cristian
>>
>> Cristian Rusu schrieb:
>>  > some code is
>>
>>> ObjectMap<String, Object> msg = new ObjectMap<String, Object>();
>>> msg.put("id", id);
>>> msg.put("txt", message);
>>>
>>> SO.setAttribute(Integer.toString(id), msg);
>>>
>>> Now how do I get that msg restored so I can read all the Map elements?
>>>
>> just cast it to the type you expect.
>> this code snipped should work for your needs:
>>
>> ObjectMap<String, Object> msg = (ObjectMap<String, Object>)
>> SO.getAttribute(Integer.toString(id));
>>
>
> Well I tried that, and got some warnings about not verified casting...
> When at runtime, I get exception about casting.

Don't worry about the warning. You just have to ensure that the object
you want to read and the object you have stored are of the same type.
But that condition is given in the example.

The ClassCastException is another problem.
Lets debug the code.
1) Ensure that the 'id' you store is the same 'id' you read from.
debug your code and compare the IDs or just try to use a fix number
instead of 'Integer.toString(id)'.
2) Get the value object for that ID
Object o = SO.getAttribute(Integer.toString(id));
2.1) check that this object is not 'null'
2.2) have a look inside the object with your debugger. has it the
expected content?
3) does anyone overwrite the attribute in the SO with another object type?

wouldn't it be easier to store the message only as
SO.setAttribute(Integer.toString(id), message);
no information would get lost ... ;)

_______________________________________________
Red5 mailing list
Red5@...
http://osflash.org/mailman/listinfo/red5_osflash.org

 « Return to Thread: Shared Object editing