Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Odd NullPointerException

$
0
0
Hello -

This is a basic simulation of my problem.

I have two classes, and a variable in one gets set, yet generates a NullPointerException.

Test.java, with my main
public class Test
{
public static void main(String[] args)
{
Ooba o = new Ooba();
o.generate();
}
}



Ooba.java, where the problem occurs
import java.util.Random;

public class Ooba
{
	private Random r;
	
	public Ooba()
	{
		new Ooba(System.currentTimeMillis());
	}
	
	public Ooba(long lol)
	{
		r = new Random(lol);
	}
	
	protected void generate()
	{
		System.out.println(r.nextDouble());
	}
}



My error:

Exception in thread "main" java.lang.NullPointerException
at Ooba.generate(Ooba.java:19)
at Test.main(Test.java:7)

Line 19 is the line where I print the next double from the Random.

Any ideas?

Thanks

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>