title: ArrayList null object reference Android
body: <p>I get this error:</p>
  
  <blockquote>
    <p>04-30 10:32:26.665: E/AndroidRuntime(13605):
    java.lang.RuntimeException: Unable to start activity
    ComponentInfo{com.ribicinc.vzemialipusti/com.ribicinc.vzemialipusti.Skatle}:
    java.lang.NullPointerException: Attempt to invoke interface method
    'java.lang.Object java.util.List.get(int)' on a null object reference</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <p>My code, first activity: </p>
  
  <pre><code>List&lt;Integer&gt; skatlice = Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  
      ...
  
      if (cases[position] == 1) {
         myIntent2 = new Intent(Game.this, Skatle.class); 
         vrednostskatel = 1;
         myIntent2.putExtra("vrednostskatel", vrednostskatel);
  
         skatlice.set(0, 1);
         myIntent2.putIntegerArrayListExtra("skatlice", (ArrayList&lt;Integer&gt;) skatlice);
  
         startActivity(myIntent2); 
         overridePendingTransition(R.layout.mainfadein, R.layout.splashfadeout);
  }
  </code></pre>
  
  <p>Second activity:</p>
  
  <pre><code> public class Skatle extends Activity {
  
          int[] skatle = new int[28];
  
          @Override
          protected void onCreate(Bundle savedInstanceState) {
  
  
      super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_skatle);
  
          Intent mIntent = getIntent();
          int cases = mIntent.getIntExtra("vrednostskatel", 0);
          List&lt;Integer&gt; skatlice = mIntent.getIntegerArrayListExtra("skatlice");
          TextView text = (TextView) findViewById(R.id.editText1);
          DecimalFormat formatter = new DecimalFormat("###,###,###");
  
          for (int i = 0; i &lt; 28; i++) {
              int amount = skatlice.get(i);
              skatle[i] = amount;
          }
  
  
          if (cases == 1 || skatle[0] == 1) {
                  TextView layout = (TextView) findViewById(R.id.textView1);
                  layout.setBackgroundResource(R.drawable.izbrano);
                  layout.setTextColor(Color.parseColor("#d7a308"));       
                  ImageView image = (ImageView) findViewById(R.id.imageOdprto);
                  image.setImageResource(R.drawable.o1);
                  String strIi = formatter.format(cases);
                  text.setText(strIi + "€");
  
                  }
  </code></pre>
  
  <p>This crash occurs on the second Activity.</p>