Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Henry Wong
author
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be quicker to just read through the JavaDocs...
 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just looked at some, I have been using those actually, just didnt know what to refer to them as.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic