« Return to Thread: Shared Object editing
sorry, but currently I don't have a glue what's wrong or an idea to help you. I store common java objects as well as Sets, Lists and some own object types and I'm always able to write/read them to/from SO.Cristian Rusu schrieb:
On Thu, Jul 9, 2009 at 18:41, javaguy <javaguy@...> wrote:
Cristian Rusu schrieb:
On Thu, Jul 9, 2009 at 14:23, javaguy <javaguy@...> wrote:
Hi CristianDon't worry about the warning. You just have to ensure that the object you
Cristian Rusu schrieb:Well I tried that, and got some warnings about not verified casting...
> some code is
ObjectMap<String, Object> msg = new ObjectMap<String, Object>();
msg.put("id", id);this code snipped should work for your needs:
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.
ObjectMap<String, Object> msg = (ObjectMap<String, Object>)
SO.getAttribute(Integer.toString(id));
When at runtime, I get exception about casting.
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 ... ;)
The ID is fine, my msg is more complex than just ID and text, just not
mentioned here.
Object o is not null but I can't much recognize it by expanding and reading
through properties in variable window, so I have no idea what is actually
extracting from SO into obj o.
Nobody work on the SO but the function that also read it.
What I try to accomplish is to edit back a msg line but keep the old msg
date and few other things related to it.
I'll dig more into the object tomorrow and see
I still use red5 v0.7. Maybe you use already 0.8? Is there a difference in storing/reading or at the ObjectMap? I don't know ...
I tried the following code in my environment.
my ID was fix (1)
ObjectMap<String, Object> msgWrite = new ObjectMap<String, Object>();
msgWrite.put("id", 1);
msgWrite.put("txt", "test");
SO.setAttribute("1", msgWrite);
Object o = SO.getAttribute("1");
try
{
ObjectMap<String, Object> msgRead = (ObjectMap<String, Object>) o;
Integer id = (Integer) msgRead.get("id");
String text = (String) msgRead.get("txt");
System.out.println(id+":"+text);
}
catch(Exception e)
{
e.printStackTrace();
}
This code run fine without any error.
Please correct me if I'm wrong with my next assumption. The objects you store inside the ObjectMap should implement Serializable. So you may have stored some object types inside the ObjectMap that do not implement Serializable?
Maybe any others have some more hints to solve your problem.
« Return to Thread: Shared Object editing
| Free embeddable forum powered by Nabble | Forum Help |