wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes enhanced for loop hangup? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "enhanced for loop hangup?" Watch "enhanced for loop hangup?" New topic
Author

enhanced for loop hangup?

Richard Chambers
Ranch Hand

Joined: Apr 03, 2008
Posts: 40
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 ]
Richard Chambers
Ranch Hand

Joined: Apr 03, 2008
Posts: 40
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
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

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.


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Richard Chambers
Ranch Hand

Joined: Apr 03, 2008
Posts: 40
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 ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

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:

Richard Chambers
Ranch Hand

Joined: Apr 03, 2008
Posts: 40
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
Richard Chambers
Ranch Hand

Joined: Apr 03, 2008
Posts: 40
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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38040
    
  22
About NullPointerExceptions (NPEs) which everybody suffers from, look for old posts about NPEs and how to handle them, like this thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enhanced for loop hangup?
 
Similar Threads
Null Pointer Exception
Where am I getting this from?
constructor
the instance variable shapes
lost n confussed