• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Need some help, pleeaaase!!

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I keep getting a null pointer exception from the paint method.
It seems that there is a null in the player.display, but I can't find it. any help would be great. Sorry, but the style seems not to have made the transition.
Thanks
B.


(code tags added by Marilyn for readability)
[This message has been edited by Marilyn deQueiroz (edited November 15, 2001).]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've just realised that my username was incorrect
oops,
sorry.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brian could you edit your post and put code tag around it.
 
Brian MacDonald
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry,
I am a complete beginner at this!!!
Also, I forgot to say. This is an assignment so I wouldn't like
help in the way of actual code. But of the life of me, I can't
see where I've went wrong. Any help any one could give me would be great, thanks
Sorry once again.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at player1, player2 and name. Look where you create instance variables and then where you use new. See anything wrong?
 
Brian MacDonald
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure, we've only started the course, and the commands I'm
using are the same as those in the book. Should I create instance
variables outside init? I'll continue to
muddle through. I'm getting the variable
coming up as null now, so is definitely just
a matter of the way I'm creating them. I've
been at this all day (I'm Scottish!!!) and
I've been stuck for a while now, I'm sure I'll get it.
thanks
[This message has been edited by Brian MacDonald (edited November 15, 2001).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that you declared them outside of init - which is fine, but then you RE-declared them inside the init() method. This effectively gave you NEW variables local only to the init() method, which you then did stuff with.
When init() was over - poof! the local variables are gone and now all that is left are the original variables which were never initialized with any values .
If you just USE the variables - without redeclaring them (by naming the variable "type"), the code in init() will use the variabled declared outside.
Player player1 = . . . // declares a variable
player1 = . . . // uses a variable without redeclaring it
[This message has been edited by Cindy Glass (edited November 15, 2001).]
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way Brian, very noble of you to only want a little help and not have someone else code it for you. In case you didn't get what Cindy pointed out.
In your Player class you define name as an instance variable.
Private String name;
Within your constructor you do:


You created another variable called name used only within the constructor. So your name instance variable is null. That is why you get the error. The other methods attempted to use name (instance variable) which was still null.
Just say
name = playerName;
Same goes for player1 and player2. I know you just wanted hints but I think now you might understand what happened.
 
Brian MacDonald
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops!!
Thank you.
 
CAUTION! Do not touch the blades on your neck propeller while they are active. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic