| Author |
Recieving an Exception Error
|
Michael Coco
Greenhorn
Joined: Sep 15, 2009
Posts: 5
|
|
First post here and am I am using Eclipse and am receiving the following error:
By the way the errors at 8 and 18 below
I know java fairly well, but for whatever reason i cannot figure out what im doing wrong.
My code
Thanks in advance
|
 |
Gamini Sirisena
Ranch Hand
Joined: Aug 05, 2008
Posts: 347
|
|
|
Have you initialized the OriginalList variable?
|
 |
Michael Coco
Greenhorn
Joined: Sep 15, 2009
Posts: 5
|
|
sorry forgot this
public static int[] OriginalList;
have it inside my public class
|
 |
Gamini Sirisena
Ranch Hand
Joined: Aug 05, 2008
Posts: 347
|
|
|
Ok. You have declared the variable. Where are you initializing it?
|
 |
Michael Coco
Greenhorn
Joined: Sep 15, 2009
Posts: 5
|
|
I guess i havent initialized OriginalList... can you give me some hints on how? I tried int[] OriginalList = new int[N];
im much better with vb and c#, sorry
|
 |
Michael Coco
Greenhorn
Joined: Sep 15, 2009
Posts: 5
|
|
Sorry it seems as if i move
before i call createrandoms(N-1) it will work properly. Can someone tell me why? why cant i initialize after i call create randoms?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
|
You will escape the NullPointerException wherever your initialisation is, provided it is before you try to use the reference. It is probably better design to initialise every instance field in your constructor.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
|
And why have you got all your methods static? You have got too much inside your main method. You ought to be creating an object, then calling instance methods on it.
|
 |
Michael Coco
Greenhorn
Joined: Sep 15, 2009
Posts: 5
|
|
Campbell Ritchie wrote:And why have you got all your methods static? You have got too much inside your main method. You ought to be creating an object, then calling instance methods on it.
No real reason, just how i set it up. When it tried calling createrandoms, i had to create it as static or i kept receiving an error
|
 |
 |
|
|
subject: Recieving an Exception Error
|
|
|