title: Getting Nullpointer Exception by adding an Arraylist to another Arraylist
body: <p>Im having an Object which has some ArrayList as propoerties as you see below. Now im trying to use these object properties (ArrayList) to put in another Arraylist, but its not working and Im getting  a Nullpointerexception. The following source code illustrates my idea:</p>
  
  <p>Class with Arraylist as object properties:</p>
  
  <pre><code>public class RawVector {
  
  
  private long size;
  private ArrayList&lt;Float&gt; x,y,z;
  private ArrayList&lt;Long&gt; time;
  
  
  public void setSize(long time){
  
      this.size = time;
  }
  
  public ArrayList&lt;Long&gt; getTime(){
  
      return this.time;
  }
  
  public void setTime(ArrayList&lt;Long&gt; time){
  
      this.time = time;
  }
  </code></pre>
  
  <p>The Class testcsv in which i fill values in the ArrayList x,y,z of the Class RawVector:</p>
  
  <pre><code> ......         ArrayList&lt;Float&gt; x = new ArrayList&lt;Float&gt;();
                  ArrayList&lt;Float&gt; y = new ArrayList&lt;Float&gt;();
                  ArrayList&lt;Float&gt; z = new ArrayList&lt;Float&gt;();
  
  
                  File n = new File("C://file.csv");
  
                  FileReader fileReader = new FileReader(n);
  
              BufferedReader reader = new BufferedReader(fileReader);
  
              for(String zeile = reader.readLine(); zeile != null; zeile = reader.readLine()){
                  StringTokenizer data = new StringTokenizer(zeile, " ,");
  
  
                  x.add(Float.parseFloat(data.nextToken()));
                  y.add(Float.parseFloat(data.nextToken()));
                  z.add(Float.parseFloat(data.nextToken()));
                  size++;
  
  
  
              }
              vector2 = new RawVector();
              vector2.setX(x);
              vector2.setY(y);
              vector2.setZ(z);
  </code></pre>
  
  <p>.....</p>
  
  <p>The Class Segementation in which I want to assign the ArrayLists of class RawVector to another ArrayList:</p>
  
  <pre><code>ArrayList&lt;Float&gt; sampleX = new ArrayList&lt;Float&gt;();
      ArrayList&lt;Float&gt; sampleY = new ArrayList&lt;Float&gt;();
      ArrayList&lt;Float&gt; sampleZ = new ArrayList&lt;Float&gt;();
  
      while(countersize &lt;= (new RawVector().getSize())){
  
  
          Windowing wid = new Windowing(); 
  
          for(int i = 0; i &lt;= m.getWsize() ; i++){
  
              if(i &lt;= (new RawVector().getSize())){
  
  
                  sampleX.add(rv.getX().get(i));
                  sampleY.add(rv.getY().get(i));
                  sampleZ.add(rv.getZ().get(i));
              }
  </code></pre>
  
  <p>I get the following Exception:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
      at Segementation.getwindow(Segementation.java:69)
      at Segementation.main(Segementation.java:95)
  </code></pre>
  
  <p>line 69 stand for: </p>
  
  <pre><code>sampleX.add(rv.getX().get(i));
  </code></pre>
  
  <p>The idea behind this line is to get the value of i in Arraylist x and to add it to the new ArrayList sampleX</p>
  
  <p>I know you will get an NullpointerException if you dont intialize your Arraylist. But I was pretty sure my ArrayList x of the class RawVector is intilaized by assigning values through the class tescsv.</p>
  
  <p>I hope my problem is straightforward. I would be very grateful for any help!!!!!!
  Thankls in advance.</p>