java - Array exception error, Point3f array -


i'm having null pointer exception error on point3f array , can't see why. happens on first pass position [0] selected. can explain this? thanks.

import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; import javax.vecmath.point3f; public class starter {  static int noofsides = 4;  public static void main(string[] args) {      point3f[] pointarray = new point3f[noofsides];      for(int i=0; i<noofsides; i++)     {         system.out.println(i+1+". input x value: ");         pointarray[i].x=readconsole();      //  pointer exception here          system.out.println(i+1+". input y value: ");         pointarray[i].y=readconsole();          pointarray[i].z=(float)0.0;     }     //  static call work out area of polygon     system.out.println("area: "+polyareatry.calarea(pointarray)); } public static float readconsole() {     string s = null;     try     {         bufferedreader bufferread = new bufferedreader(new inputstreamreader(system.in));         s = bufferread.readline();     }     catch(ioexception e)     {         e.printstacktrace();     }     float f = (float)float.parsefloat(s);      return f; } 

}

elements of object array null default. initialize elements within array prior attempting access fields

for (int = 0; < noofsides; i++) {    pointarray[i] = new point3f();     ... } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -