dimanche 10 janvier 2016

NullPointerException in generating random numbers [duplicate]

I get a NullPointerException at line 14 the one that says: points[i].x = new Random().nextInt(30);

import java.util.Random;

public class RandomPoints {
    public class Point {
         public int x;
         public int y;
    }

    public static void main(String[] args) {
        Point[] points = new Point[100];
        for(int i = 0; i < points.length; i++) {
            points[i].x = new Random().nextInt(30);
            points[i].y = new Random().nextInt(30);
            System.out.println(points[i].x + " " + points[i].y);
        }           
    }
}




Aucun commentaire:

Enregistrer un commentaire