ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!

Jump to content



Photo

Noob Java Question Keep Getting NullPointerException :(


  • Please log in to reply
Noob Java Question Keep Getting NullPointerException :(

#1

GenghisKhan2
GenghisKhan2
    Offline
    0
    Rep
    13
    Likes

    Advanced Member

Posts: 136
Threads: 7
Joined: Sep 01, 2017
Credits: 0
Six years registered
#1

s


Edited by GenghisKhan2, 22 April 2018 - 09:10 PM.

  • 2

#2

nerdist
nerdist
    Offline
    0
    Rep
    0
    Likes

    Member

  • PipPipPip
Posts: 30
Threads: 1
Joined: Apr 23, 2018
Credits: 0
Six years registered
#2

NullPointerException occurs when you declare a variable but did not create an object. If you attempt to dereference that variable before creating the object you get a NullPointerException

 

Let us take a look at the full code .


  • 0

#3

RamHerHard
RamHerHard
    Offline
    0
    Rep
    0
    Likes

    New Member

Posts: 10
Threads: 0
Joined: May 05, 2018
Credits: 0
Five years registered
#3

i can probably help! PM if you want


  • 0

#4

Logerlala
Logerlala
    Offline
    0
    Rep
    2
    Likes

    Advanced Member

Posts: 132
Threads: 1
Joined: Feb 11, 2018
Credits: 0
Six years registered
#4

Please share your code here, I can help


  • 0

#5

FranckCastle
FranckCastle
    Offline
    0
    Rep
    12
    Likes

    Night is dark and full of terrors.

  • PipPipPip
Posts: 25
Threads: 0
Joined: May 04, 2019
Credits: 0
Four years registered
#5

You probably forgot to instantiate the objects you create (use the keyword "new"). 

 

Example of the use of the keyword "new" :

 

public class A{

         

               //attributes

 

               //constructor

               Public A(){...}

 

               //methods

}

 

public class MAIN{

 

public static void main(String args[]){

 

               A a = new A(); 

       

               //rest of the code

}

}

 

Nota Bene :

If you use arrays in your code, you must do the same manipulation, declaring them isn't enough, you should instatiate them.

 

                   private int[] myArray = new int[Constant]  //Constant is an integer already defined (The length of the table). ex : 10.


Edited by FranckCastle, 05 May 2019 - 11:42 AM.

  • 0

#6

Zifukoro
Zifukoro
    Offline
    0
    Rep
    3
    Likes

    Advanced Member

  • PipPipPipPip
Posts: 89
Threads: 0
Joined: Apr 28, 2019
Credits: 0
Four years registered
#6

Share it i can help you man


  • 0


 Users browsing this thread: