0

I am a beginner and i wan to know what is 'java.lan.NullPointerException' and how to fixe this error?

Method invocation 'getInt' may produc 'java.lan.NullPointerException'

applecrusher
  • 5,508
  • 5
  • 39
  • 89

1 Answers1

0

I am a beginner and i wan to know what is 'java.lan.NullPointerException' and how to fixe this error?

A NullPointerException occurs when you try to use a variable that isn't instantiated. For example, let's say you have a variable called myVar, and you want to execute the function myFunc(...) on myVar, and it, for some reason, gives you a NullPointerException. The reason this happens is that you haven't created an object (instantiated) it. You need to do myVar = new MyClass() before you can use it. Examine the following code:

MyClass myVar;          // Defines a MyClass variable called myVar.
myVar = new MyClass();  // Creates an instance of MyClass and assigns it to myVar.
myVar.myFunc();         // Now you can execute myFunc() on myVar.

Please read another post explaining NullPointerExceptions before creating your own, as duplicates aren't allowed on StackOverflow. Also, please consult How to create a Minimal, Complete, and Verifiable example when creating future questions, as well as when editing your old posts.

Also, keep in mind that this post is a duplicate of What is a NullPointerException, and how do I fix it?

Finally, as for this:

Method invocation 'getInt' may produc 'java.lan.NullPointerException'

You need to explain where you're getting this getInt() function.

For now, my recommendation is you remove the "what is a NullPointerException", and expand the getInt() stuff, try showing us your code!

Also, if my question answered your question, please mark as answered.

Johannes
  • 377
  • 1
  • 5
  • 16