• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException I dont understand how to fix, Been working on it for 6 hours now

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Argh, Im really annoyed. I've been working on an IRC client in a game i've been editing, and well. I just dont know how to solve this..

i'm getting nullpointerexception at "mc.thePlayer.addChatmessage(str);" (Line 65)



I'm not really sure what else you will need, So just ask!

If you help me solve this ill be very grateful!
 
Ranch Hand
Posts: 66
Android IntelliJ IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where do you create an instance of Minecraft and assign that to the mc var?

 
Ryan Ramsdenr
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I don't understand. What do you mean by that?

I tried;

 
Keith Rainey
Ranch Hand
Posts: 66
Android IntelliJ IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was looking for a reason for the null pointer exception. The code you posted did not show any assignment to the mc variable.

If the object variable doesn't refer to an object and you try to access a member, you will get a NullPointerException.
 
Ryan Ramsdenr
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, But how do I fix it? (Sorry for my lack of Understanding, I'm New to Java)
Also thankyou for your help so far!
 
Keith Rainey
Ranch Hand
Posts: 66
Android IntelliJ IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




You need to verify that the the minecraft parameter is receiving an actual instance.

I will assume you are calling this particular constructor when you create a new IRC and not a no-argument constructor like new IRC()
 
Ryan Ramsdenr
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm calling it by,



How should I be calling it?
 
Keith Rainey
Ranch Hand
Posts: 66
Android IntelliJ IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ryan Ramsdenr wrote:I'm calling it by,



How should I be calling it?



I'm making some assumptions here based on the code fragments you've given.

Here you are making a call to a static method in the IRC class. Presumably mc.thePlayer.username is a String which you pass to the main(String name) method.
This is not instantiating an object of the IRC class. You are accessing the class members (static methods and variables).
The Public IRC() constructor you posted earlier does not execute except when you create a new instance. Nothing you've given shows that you are creating a new instance.
If the constructor doesn't run, then the mc variable doesn't get set.
If the mc variable doesn't get set, you get a NullPointerException when you try to access its contents (which don't exist).


Try throwing a couple of debugging lines into the constructor:





That will tell you whether or not that constructor is being called or not.
 
She's out of the country right now, toppling an unauthorized dictatorship. Please leave a message with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic