title: android - java.lang.ArrayIndexOutOfBoundsException: length=4; index=4 length array - Stack Overflow
body: <p>I got this error in android studio:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                Process: com.bravo.developers.pak.indo.yaami.recipes.free, PID: 21865
                java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bravo.developers.pak.indo.yaami.recipes.free/com.bravo.developers.pak.indo.yaami.recipes.free.GridDetailActivity}: java.lang.ArrayIndexOutOfBoundsException: length=8; index=14
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2534)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614)
                    at android.app.ActivityThread.access$800(ActivityThread.java:178)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
                    at android.os.Handler.dispatchMessage(Handler.java:111)
                    at android.os.Looper.loop(Looper.java:194)
                    at android.app.ActivityThread.main(ActivityThread.java:5653)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at java.lang.reflect.Method.invoke(Method.java:372)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                 Caused by: java.lang.ArrayIndexOutOfBoundsException: length=8; index=14
                    at com.bravo.developers.pak.indo.yaami.recipes.free.GridDetailActivity.onCreate(GridDetailActivity.java:71)
                    at android.app.Activity.performCreate(Activity.java:6100)
                    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
                    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)
                    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2614) 
                    at android.app.ActivityThread.access$800(ActivityThread.java:178) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470) 
                    at android.os.Handler.dispatchMessage(Handler.java:111) 
                    at android.os.Looper.loop(Looper.java:194) 
                    at android.app.ActivityThread.main(ActivityThread.java:5653) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at java.lang.reflect.Method.invoke(Method.java:372) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) 
  </code></pre>
  
  <p>W/MALI: glDrawArrays:714: [MALI] glDrawArrays takes more than 5ms here. Total elapse time(us): 5229
  I/Process: Sending signal. PID: 21865 SIG: 9
  Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'</p>
  
  <p><br>
  <strong>This is the code:</strong></p>
  
  <pre><code>public class GridDetailActivity extends AppCompatActivity {
  
      int position;
      private ImageView imageView;
      private TextView textView;
      private TextView dtextView;
      private TextView titletextView;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_grid_detail);
  
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Snackbar.make(view, "jojo", Snackbar.LENGTH_LONG)
                          .setAction("Action", null).show();
              }
          });
  
  
          // Set tile for the ViewPager
          setTitle(" Grid Details Activity ");
  
          // get intent data
          Intent i = getIntent();
          position = i.getExtras().getInt("id");
  
          MyGridAdapter gridAdapter = new MyGridAdapter(this);
          // List&lt;MyGridAdapter.Item&gt; mItems = new ArrayList&lt;MyGridAdapter.Item&gt;();
  
          List&lt;ImageView&gt; mItems = new ArrayList&lt;ImageView&gt;();
  
          // Retrieve all the images
          for (int position = 0; position &lt; gridAdapter.getCount(); position++) {
              ImageView imageView = new ImageView(this);
              imageView.setImageResource(gridAdapter.mThumbIds[position]);
              imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  
              mItems.add(imageView);
          }
  
          imageView = (ImageView)findViewById(R.id.image_grddetails);
          imageView.setImageResource(gridAdapter.mThumbIds[position]);
  
          textView = (TextView)findViewById(R.id.description_TextView);
          textView.setText(gridAdapter.mDescriptionTXT[position]);
  
          dtextView = (TextView)findViewById(R.id.details_text);
          dtextView.setText(gridAdapter.Ingredients[position]);
  
          titletextView = (TextView)findViewById(R.id.restitle);
          titletextView.setText(gridAdapter.mRecipeTitle[position]);
  
  
      }
  }
  </code></pre>
  
  <p>I don't know how to manage the array length problem.</p>
  
  <p>I just added the new elements to the list, but I don't know if this is the right form to do it.</p>
  
  <p>Do I need to resize my array?</p>