Saturday, April 13, 2013

[android help] Android ArrayIndexOutOfBoundsExeption When Viewing Image

arrays - Android ArrayIndexOutOfBoundsExeption When Viewing Image - Stack Overflow




















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 Java.lang.ArrayIndexOutOfBoundsExeption. Any ideas as to what I need to do to get this to viewing the image? Below is my 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);
}
});
}




























Not sure but I believe dia.show(); should be called at the very last - i.e after view.setOnClickListener.























From where did this ArrayIndexOutOfBoundsException get thrown? I'm assuming it's thrown when you access arrPath[i]. How do you figure that the view's id should be an index into arrPath? That seems to be the problem.




















default







.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...