Forums Register Login

enhanced for loop hangup?

+Pie Number of slices to send: Send
Another lesson learned.

Just because all 11 class files compile doesn't mean it works.

I hate to ask this, but I'm in the final hours of this class
and time is running out. Someone please have pity and get me
going in the right direction.

I've "isolated" my problem to this method by debugging,
but have no idea why this method is hanging up.

Here's the pseudo code I wrote off of:


and here's my coding for it:




again I appologize, I hate to just post code.

my "guesses" would be in the instance variable shapes declaration,

or
my assignments of the shapes[index]

I've also tried to write it as Shape shapes = new Shape format

and it compiles, but still hangs the program up.

Thanks
[ May 09, 2008: Message edited by: Richard Chambers ]
+Pie Number of slices to send: Send
An update

it's hanging in the first if loop with the circle

why?

I've also gone back to my original thinking in the coding

I'm now using

Circle shape = new Circle format

that could still be wrong but seems to make more
sense to my muddled mind.

Thanks again for the help
+Pie Number of slices to send: Send
First of all, we don't know what you're trying to do. If you can give us more clear explanation of what you're trying to and what problem that you face, we might be able to help.
+Pie Number of slices to send: Send
sprinkle System.out.println() statements through your code, and print out various things - "in this loop", "whatever variable is now", etc.

this will give you a good idea as to what your program is doing when you can't see things.
+Pie Number of slices to send: Send
am I "interpreting" this right?

the pseudo code




my coding:



or is it this:



This is where the debugger is hanging, it just keeps looping at this command.

I also have proven my eyes are bad in previous problems.
I don't always see the obvious.
Have I missed a bracket? I don't think so,
and have checked, rechecked, marked, etc ...
but I still make mistakes
MANY mistakes.

Thanks
[ May 09, 2008: Message edited by: Richard Chambers ]
+Pie Number of slices to send: Send
I have re-formatted your code, to make it a little easier to read. see if you can find the problem now. it should be pretty obvious:

+Pie Number of slices to send: Send
AAAACK

now I have a NullPointerException error

thats a new one for me

The line the runtime points to is my for loop in the main method

again, the pseudo code is:



my coding is:



I think this is right. I'm not familiar with
NullPointerException, not really sure what
it means or where to look to fix it.

Thanks

btw, dang brackets, got me out of the if loop though
+Pie Number of slices to send: Send
I'm still proofing and pulling hair,
so I'm going to post more info and pray for help.

here's the for loop pseudo code:




and here's my coding:




I HATE posting code like this and fishing,
but believe me, I've checked everything I know about
and have spent hours on this before asking for help.

I know it will be something obvious that I'm just missing,
but that's the benefit of extra eyes.

Thanks for all your help.

Last assignment for this dang class, due tonight
and I have an A so far, don't want to blow it on
a silly "for" loop.
+Pie Number of slices to send: Send
About NullPointerExceptions (NPEs) which everybody suffers from, look for old posts about NPEs and how to handle them, like this thread.
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1646 times.
Similar Threads
Null Pointer Exception
the instance variable shapes
lost n confussed
constructor
Where am I getting this from?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:17:46.