Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid ArrayIndexOutOfBoundsExeption When Viewing Image
    primarykey
    data
    text
    <p>I have a simple app that when you click on an image from a GridView, a Dialog pops up with a Button that says View. When you click the Button, I want to view the image that has been clicked in the gallery. I can get this to work without a problem when I have the app navigate to the gallery without a dialog, but I need it to hit a dialog first. The error my LogCat is returning <code>Java.lang.ArrayIndexOutOfBoundsExeption</code>. Any ideas as to what I need to do to get this to viewing the image? Below is my code.</p> <pre><code>public void onClick(View v) { Dialog dia = new Dialog(ViewGrid.this); dia.setContentView(R.layout.viewimage); dia.setTitle("What To Do?"); dia.show(); dia.setCancelable(true); Button button = (Button)dia.findViewById(R.id.viewImage); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int id = v.getId(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + arrPath[id]), "image/*"); startActivity(intent); } }); } </code></pre> <p>I am getting the error on this line: </p> <pre><code>intent.setDataAndType(Uri.parse("file://" + arrPath[id]), "image/*"); </code></pre> <p>I figured it out! The below code is the working code. I needed to set my my Id that I got from the view to be from the click of the image, and not from the click of the View button. Thank you everyone for your assistance!</p> <pre><code>public void onClick(final View viewIt) { Dialog dia = new Dialog(ViewGrid.this); dia.setContentView(R.layout.viewimage); dia.setTitle("What To Do?"); dia.show(); dia.setCancelable(true); Button button = (Button)dia.findViewById(R.id.viewImage); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int id = viewIt.getId(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setDataAndType(Uri.parse("file://" + arrPath[id]), "image/*"); startActivity(intent); } }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload