How to extract an array from an Object array object.

Put your problem here if it does not fit any of the other categories.

How to extract an array from an Object array object.

Postby guitarbaka » Thu May 28, 2009 7:38 pm

I know this sounds confusing and this is a java question. So I explain more in detail.

I am calling an XMLRPC server in my android project which returns an array

Object[] returnArray = (Object []) client.call("returnArray");

returnArray is an array of objects, however returnArray[3] is an object array itself. How can I grab this object array so I can view and use its objects? Thanks
guitarbaka
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri May 22, 2009 2:19 am
Location: Pomona, CA

Top

Postby padde » Thu May 28, 2009 10:40 pm

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Object[] returnArray = (Object []) client.call("returnArray");
  3.  
  4. Object[] return3Array = (Object []) returnArray[3];
  5.  
  6.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


if returnArray[3] is a object array this should work...
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby guitarbaka » Fri May 29, 2009 1:26 am

Thank u for your response. I have tried this already, but when I do this on the logger:

Log.i("This is my first element",return3Array[0].ToString());

I get

my first element(732): [Ljava.lang.Object;@4358a088

I need to be able to get the actual value. Thank you.
guitarbaka
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri May 22, 2009 2:19 am
Location: Pomona, CA

Postby padde » Fri May 29, 2009 2:14 am

this is the right output for an object array..
is it a string array? or what do you expect?
if its string try (String[]) casts..

--- Edit ---
if this doesnt work try to cast each element of that array into string
like this:

Log.i("This is my first element", (String)return3Array[0]);



Greets Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Postby guitarbaka » Fri May 29, 2009 4:15 am

First element is a string, after two doubles ( for long and lat).

I tried this casting and I get an exception:

05-29 12:13:36.409: ERROR/AndroidRuntime(769): Caused by: java.lang.ClassCastException: [Ljava.lang.Object;

hmmm. The server that I am calling is web2py, could it be the way it stores the objects into the array that causes the problem?
guitarbaka
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri May 22, 2009 2:19 am
Location: Pomona, CA

Postby padde » Fri May 29, 2009 4:23 am

hmm maybe.. try datainputstream as far as i know datastreams takes care of
datatype sizes and that kind of stuff.
Last resort would be to serialize that original array to XML and parse it in your app.
Or you could share some code we all could play with to find a solution.


Greets Padde
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Postby guitarbaka » Fri May 29, 2009 6:38 am

So far I cant figure out the datainput stream with an array, but I will keep looking,
As for sharing some code, its kind of impossible as I would have to share the whole code and well Im trying to code apps as a way of turning it into a business. I have a log in screen which checks user name and password and then returns an MD5 for that user to be identified every time he asks the server to return him something. Anyways, thank you for all your help. Maybe sending an array of usernames and long lat is better than sending an array of an array.
guitarbaka
Junior Developer
Junior Developer
 
Posts: 13
Joined: Fri May 22, 2009 2:19 am
Location: Pomona, CA

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 32 guests