Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enhanced for loop hangup?

 
Richard Chambers
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12202
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Chambers
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12202
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50266
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
About NullPointerExceptions (NPEs) which everybody suffers from, look for old posts about NPEs and how to handle them, like this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic