title: How to fix dispatchUncaugthException in java
body: <p>I was trying to generate an array with random numbers, but it continues to show <code>dispatchUncaughtException</code>. I am totally new to java, could someone help me to figure this out?</p>
  
  <p>The codes that I wrote are as follows:</p>
  
  <pre><code>public class FindfreieGroundwaterlevel {
  
      public static void main(String[] args) {
          double[] groundwaterDistance = {-0.01,1.2,0,4.5,6.3,8.2,0,-1.7,2.1,0};
          int [] index = new int [groundwaterDistance.length]; 
          int zero = 0;
          for (int n = 0; n &lt; groundwaterDistance.length; n++ ) {   
              if (groundwaterDistance[n] == 0) {
                  index[n] = n; 
              }else{
                  index[n] = 0;
                  zero++;
              }
          }             
          int[] newindex = new int[index.length - zero];
          int j = 0;
          for(int m : index) {
              if( m!= 0 ) {
                 newindex[j] = m;
                 j++;             
              }
          }   
          for (int i: newindex) {
              System.out.println(i);
          }
  
          Random generator = new Random(10);
          Coordinate[] position = new Coordinate[20];
          for (int i = 0; i &lt;position.length; i++) {
              position[i].x = generator.nextDouble();
              System.out.println("x :" + position[i].x);
              position[i].y = generator.nextDouble();
              System.out.println("y :" + position[i].y);
              position[i].z = generator.nextDouble();
              System.out.println("z :" + position[i].z);            
          }
      }   
  }
  </code></pre>
  
  <p>The other class called <code>Coordiante</code> is:</p>
  
  <pre><code>public class Coordinate {
      public double x;
      public double y;
      public double z;
  }
  </code></pre>
  
  <p>And this is an image of the exception I got:</p>
  
  <p><a href="https://i.stack.imgur.com/ZLaEw.png" rel="nofollow noreferrer">Exception image</a></p>