aspose file tools*
The moose likes Java in General and the fly likes java.util.ArrayList is not compatible with class java.lang.String exception (SOLVED) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.util.ArrayList is not compatible with class java.lang.String exception (SOLVED)" Watch "java.util.ArrayList is not compatible with class java.lang.String exception (SOLVED)" New topic
Author

java.util.ArrayList is not compatible with class java.lang.String exception (SOLVED)

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I had code working that took data froma web service, parsed it, and loaded the values into a list that I could use in a rich:tree. This was working just fine when it took the data from this xml:



But now I need to convert it to take the data from a different xml set up that looks like this:



But when I did so I get this exception:



So it is obvious that ther is a problem with parsing this new xml due to the fact it has these three lines:



Things were fine when it was only parsing Strings, but there is a problem with the parsing of the ArrayLists.
I'm not sure where to look to find the problem and how to solve it honestly.
If I were to guess I would say there will need to be a change made to:



But I really do not know where. If it is any help, here is the class that calls the xml parser, and then loads the values to a list.



As soon as I try to call loadProjectNodes I get that exception though.

I have to get this working by Tuesday. May seem like plenty of time but with my track record on these kind of things...


True wisdom is in knowing you know nothing - Socrates
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18139
    
  39

If I had to take a guess, I would say you are using your simple framework, in a fashion that it was not intended.



But if you want to look into anyway,the first place to start would be line 105.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I have been looking at each line, but I am not able to make a lot of sense out of it honestly.

I tried working backwards, and I am able to get to the point where I have a method that calls the web service url, and takes that data that is in xml form and converts it to a Stream. By converting that to a String I was able to see that the values of the contents of that stream look like:

<measurementProjectCollection>
<measurementProject>
<projectId>wsnPondMeasurements</projectId>
<name>WSN Pond Measurements</name>
<permissions class="java.util.ArrayList"/>
<devices class="java.util.ArrayList"/>
<channels class="java.util.ArrayList"/>
</measurementProject>
<measurementProject>
<projectId>2</projectId>
<name>Matt Test Two</name>
<permissions class="java.util.ArrayList"/>
<devices class="java.util.ArrayList"/>
<channels class="java.util.ArrayList"/>
</measurementProject>
<measurementProject>
<projectId>exampleProject1</projectId>
<name>exampleProject1</name>
<permissions class="java.util.ArrayList"/>
<devices class="java.util.ArrayList"/>
<channels class="java.util.ArrayList"/>
</measurementProject>
<measurementProject>
<projectId>1</projectId>
<name>matt</name>
<permissions class="java.util.ArrayList"/>
<devices class="java.util.ArrayList"/>
<channels class="java.util.ArrayList"/>
</measurementProject>
</measurementProjectCollection>

So it is gettign that far, I have a stream that contains the contents of the web service xml. So then that is being passed to the readXML method.




Now when I check through the errors in the stack, it seems the value being passed is not passing this test:



because here is the code that clicking that first line directs me to:



And this is about as far as I can talk myself through this. The stream that is being passed does not pass the isCompatible test, but Im unsure why or how to fix it.

So if your sayign the simple framework is not being used as intended, do you think that means I need to have the web service itself changed? Or do you think there should be a way to handle this in my java code?

edit - or is the problem that I am trying to load a list with some string values and three arrays? Is that possible? I dont think I am even getting to the point of loading up the list though, or am I mistaken?

edit 2 - do you think if I removed the class="java.util.ArrayList" from those three nodes, and instead just made these nested nodes it would work for me?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18139
    
  39

So if your sayign the simple framework is not being used as intended, do you think that means I need to have the web service itself changed? Or do you think there should be a way to handle this in my java code?


I think that you should consult the documentation (or the colleague who did the framework) to best figure out how to use the framework. Anything that we suggest here is just a shot in the dark, as we never used the framework.

Henry
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Ah I see. Yeah I did email the person who came up with the simplexml code for this project, but unfortunately I wont hear from him until monday.
Thanks, I will try to find out what I can
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Matt Kohanek wrote:Ah I see. Yeah I did email the person who came up with the simplexml code for this project, but unfortunately I wont hear from him until monday.
Thanks, I will try to find out what I can


Well i didnt have to wait I figured it out myself

In my measurementProject class I had declarations for devices, permissions, and channels (the three that were giving me trouble) but I had them declared as Strings instead of an ArrayList. I changed that, and then I had one other problem, but all I had to do was change my properties field from required=true to required=false, and it worked immediately.

The way I figred it out was, I just played around with that readXml method, by erasing methods that came after a period,
Then I would hit the period so it would pop up with the list of all possible methods, along with descriptions of what they did, and I read through those. In doing so I got a better understanding of how simplexml works, and then the idea just came to me (after reading through a few more lines in the stack).

Thanks again for telling me about that Henry, I never knew before that you could click the stack errors to get a description of what it was referring to. That has already helped me resolve two iussues on my own that in the past I would have needed help on.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It might be quicker to just read through the JavaDocs...
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Well seeing as how I dont even know what those are...

I will look it up though, the tips Ive gotten so far have been invaluable

thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

JavaDocs are the standard Java documentation for the libraries you've been using, like the Java 1.5 API, for example.
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

I just looked at some, I have been using those actually, just didnt know what to refer to them as.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.util.ArrayList is not compatible with class java.lang.String exception (SOLVED)
 
Similar Threads
Need help with iteration problem (adding an Object to a List for every instance of that Object)
need help choosing best tag for this
Looking for correct data type to take in stream of xml
Is a Map data type that holds three objects possible?
Using SimpleXml, having issues with nested nesting collection within a collection