I have a class that has TreeNode data; with setters and getters. Im trying to bind values to data by using setData but I need to know how to see what the value is of what Im binding to data. How should I go about this?
The only way I know to do this as of right now is to go ahead and bind it to the tree it will eventually be used to display. But if I could check what is being bound to data before that it would take out an element of uncertainty
True wisdom is in knowing you know nothing - Socrates
I think I have it figured out, if in my class that has the data variable I put a print method:
and then put a main method in another class that is manipulating the data through the setData method:
IF I am able to get the value of data to change with this class it should come out when I run this class right?
edit - nope, I changed it from a TreeNode to a String an dthen just did node.setData("value"); and it still printed out null - Im so sidetracked now, I need to get back to my original problem but I am stuck and cant seem to get it figured out
IF I am able to get the value of data to change with this class it should come out when I run this class right?
edit - nope, I changed it from a TreeNode to a String an dthen just did node.setData("value"); and it still printed out null - Im so sidetracked now, I need to get back to my original problem but I am stuck and cant seem to get it figured out
To be blunt, I have no idea what you are trying to say... Care to show us with an example?
Im sorry, I know it is unclear, dont worry about this one, i actually found a different way to test some of this. It turns out I am not even getting as far as that. Instead I am trying to print deviceColelction from this class:
But I get a null pointer exception. So it seems to me that deviceCollection is not getting the value that Im trying to set it to. But I really dont know where to start to fix this. Im pretty much just floundering here which is the assumption most regualrs to these forums have already come to Im sure lol
But I get a null pointer exception. So it seems to me that deviceCollection is not getting the value that Im trying to set it to. But I really dont know where to start to fix this.
You "start" with the NPE. The stacktrace should provide you with the filename and line number, along with the call stack, on how you got there. Don't assume. Confirm the null pointer exception.
Hmm, OK. I didnt know this, thanks. Here is the full stack:
Exception in thread "main" java.lang.NullPointerException at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:80)
at org.simpleframework.xml.core.Persister.read(Persister.java:471)
at org.simpleframework.xml.core.Persister.read(Persister.java:452)
at deviceContainer.DeviceCollectionXMLAO.readXML(DeviceCollectionXMLAO.java:15)
at testContainer.Temp.updateNode(Temp.java:44)
at testContainer.Temp.main(Temp.java:25)
Im gonna do a search for some of that and see what I can get
If I change the code around a bit by removing both of the throws from the main and updateNode class, eclipse then tells me I need to add a ctach/throw declaration which i do and then I must initialize deviceColelction which I do to null. The code changes to this:
WHen I run that i get
java.lang.NullPointerException printingnull
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:80)
at org.simpleframework.xml.core.Persister.read(Persister.java:471)
at org.simpleframework.xml.core.Persister.read(Persister.java:452)
at deviceContainer.DeviceCollectionXMLAO.readXML(DeviceCollectionXMLAO.java:15)
at testContainer.Temp.updateNode(Temp.java:46)
at testContainer.Temp.main(Temp.java:26)
Exception in thread "main" java.lang.NullPointerException at testContainer.Temp.updateNode(Temp.java:57)
at testContainer.Temp.main(Temp.java:26)
so at least it is printing out the string I put in the println ("printing") but then after that it has null, so it seems the deviceCollection is staying null which is what i initialized it to. I think that also suggests that deviceColelction is just not being set to what I am trying to set it to
man I might just have to use a .properties file to poulate my tree nodes, and get this project running as far as I can in that manner. Then once I have all that complete, if there is still time at the end I can try to return to this problem. I just cant get a richfaces tree to populate from xml, it is so frustrating
Basically... The readXML() method has been called, which means that the method.getResponseBodyAsStream() call did return a value. Unfortunately, there is something wrong with the value. If you have the source to the simple framework, take a look at the Persister class, particularly line 471 -- you need to figure out what that line is accessing, and why the value that was passed in was invalid.
so at least it is printing out the string I put in the println ("printing") but then after that it has null, so it seems the deviceCollection is staying null which is what i initialized it to. I think that also suggests that deviceColelction is just not being set to what I am trying to set it to
Of course deviceCollection is staying null. The assignment is failing. There is no value (returned from readXML()) to set it to. The exception aborts the assignment. You didn't need to make all those code changes to confirm that.
I hate to ask but youve been more helpful than anyone so far in teaching me a very valuable skill - how to troubleshoot. I didnt even knwo i could look at this stuff,.
So maybe if you dont mind youd help me interpret what I got when I clicked on java:471 (and finally figured out what you meant by the source 0 I have no idea how I lucked out and interpreted what that meant but I did)
Just get comfortable with the stack trace. If you go up (the stack) by one, you'll see that it failed during the constuctor of the InputStreamReader() which means that it is either the second or third parameter of that method that is null.
To see how that method is called, go down the stack by one -- specifically, take a look a line 452 of the same file.
(And the readXml() method makes me nervous, because it's closing the input stream, but where it's opened is anybody's guess--methods with side effects like that can be unnecessarily difficult to debug, and give me the heebie-jeebies. That's not really related to your issue, though.)
Removing "= null" from "DeviceCollection deviceCollection = null;" shouldn't change program behavior: deviceCollection will be null anyway if it's not explicitly set.
I can probably use system.out.println(method.getResponseBodyAsStream()); to see what value is being passed to access.readXml right?
Man I wish I wasnt at work so I could work on this more
or wait would I need to use method.getResponseBodyAsString when printing out the value?
If you were in my shoes, what would you be looking into? I guess what would be the terms you search for? Im definitely willing to do the work, I just dont really have a starting point to go from
I posted this as its own topic but I also want to put it here since they are really the same problem:
When I print out some values to see what they are I get:
The first line, responseBody is of the type InputStream The second line deviceCollection of the type DeviceCollection, in teh deviceContainer - It is this line I am mainly concered with. It is a stream so I had no idea what to expect when I print it out, just as long as it wasnt null!! But I dont know what to make of printing deviceCollection: deviceContainer.DeviceCollection@1764be1 - does this mean I actually was able to bind the responseBody to deviceCollection as a stream? (through this line: deviceCollection = access.readXML(method.getResponseBodyAsStream(null));)
And the third line data is of the type TreeNode, but that line is pretty obvious
So Im unsure how to interpret this. The first line seems to suggest it is working correctly right, because it is calling an auto close method on the stream right? However when I change some things in that class and try to also print out responseBody as a String, I get:
I think this also might be OK though, because if Im right it is saying it received the data I wanted and printed it out as a string, but when it also tried to print it as the stream, the stream was already closed. I think this is what this means, please clear this up for me though. deviceCOllection form teh third line also changes to null when I do this, but I would guess that is also the result of the stream being auto closed right?
It is this second line that Im mainly concerned with. Im trying to bind the responseBody which is that xml to deviceCollection. It seems I was successful in that first bit up there right? Or am I misinterpreting?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: How can I use println to display the value of data when I node.setData((TreeNode) deviceCollection..