Dumb question I have another thread going for my nullPointerException error and am still troubleshooting it but I'm wondering if this might be the problem, or just something I'm not getting at the moment.
Our class has us coding from pseudo code. Not a good way to learn Java.
the pseudo I have a question about is this:
This is my coding for the class it appears in:
Sorry to use so much code for the question. What I'm wondering is ---- where does currentShape come from. I have 11 class files in this project, and I'm not defining it anywhere that I can see. This is early in the main method, so it should be defined and initialized or assigned or whatever before I'm using it, but if it's there I'm blind. Did the teacher throw a curve and I'm using the wrong name maybe? or is this some internal JAVA thing that's refering to the array created in myFields. It has a shape field in it.
The more I learn the more confused I get
I need to get this running and turned in tonight, last project of the semester.
Java will let you declare variables of the same name in different scopes.
That's why you can do things (example is for an instance variable):
Since you delcare a new reference, Shape shapes, it's this reference shapes that loadShapesArray will use. It then promptly marks it eligible for GC when you leave loadShapesArray(), and you lose all the work you did to load your array. The class static variable shapes is still null, hence your NPE.
I think you'll find if you modify
that you'll be using the ShapeTest private static shapes as you are intending. [ May 09, 2008: Message edited by: Stevi Deter ]
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James