This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This is not the whole program. But basically the program takes a <path> tag (or multiple path tags) from a scalable vector graphic file and converts it to a string and then removes n% unimportant points that the user decides.
Thanks to all those who can help!
This is the error that I am receiving when I go to test my code with an actual SVG file:
I did some research and found that this error is caused by probably one of these three:
- Attempting to invoke an instance method of a null object
- Attempting to access or modify a particular field of a null object
- Attempting to obtain the length of such null object as an array
I have failed to locate the problem. Any suggestions on where in this code I can look for the problem and possibly a hint on what the specific problem is?
Here is a code snippet that ends on line 54 of my SVG.java file
William Koch wrote:If Paths is null why can I not add something to it.
Because it's null. The Paths variable holds a reference whose value is null--that is, a reference that doesn't point to any object. You have to create your ArrayList object before you can call methods on it. You can't call methods on a null reference.
I declared Paths in line 6.
Declaring a variable != creating an object.
Is there a simple fix?
Do I need to give Paths some initial value?
You have to give it a non-null value before you dereference it. The most appropriate place in this case is probably the line where you declare it, but it doesn't have to be there.
I am new to Java if you haven't noticed. My first language was Ada95 but now I am having to learn Java as they try to teach me data structures. I am in my second programming course for my undergrad in Computer Science (it is a Data Structures course).
I appreciate all the help you give here at The Ranch