当我单击应用程序中的URL图像或目录时,我失去了联系,这是我的代码和错误,
设置GridView方法
private void setupGridView(String stringDirectory) {
Log.d(TAG, "setupGridView: directory chosen: " + stringDirectory);
final ArrayList<String> imgURLs = FileSearch.getFilePath(stringDirectory);
//set the grid column width
int gridWidth = getResources().getDisplayMetrics().widthPixels;
int imageWidth = gridWidth / NUM_GRID_COLUMNS;
gridView.setColumnWidth(imageWidth);
//use the grid adapter to adapter the images to gridview
GridImageViewAdapter adapter = new GridImageViewAdapter(getActivity(), R.layout.layout_grid_image_view, mAppend, imgURLs);
gridView.setAdapter(adapter);
//set the first image to be displayed when the activity fragment view is inflated
setImage(imgURLs.get(0), glImageView, mAppend);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemClick: selected an image: " + imgURLs.get(position));
setImage(imgURLs.get(position), glImageView, mAppend);
}
});
}
当我尝试单击没有图像的目录时出现此错误。
错误
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:411)
at com.tugasakhir.batikdetections.fragment.batiklopedia.InputFragment.setupGridView(InputFragment.java:154)
at com.tugasakhir.batikdetections.fragment.batiklopedia.InputFragment.access$100(InputFragment.java:37)
at com.tugasakhir.batikdetections.fragment.batiklopedia.InputFragment$3.onItemSelected(InputFragment.java:129)
at android.widget.AdapterView.fireOnSelected(AdapterView.java:936)
at android.widget.AdapterView.dispatchOnItemSelected(AdapterView.java:925)
at android.widget.AdapterView.-wrap1(AdapterView.java)
at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:895)
at android.os.Handler.handleCallback(Handler.java:836)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:232)
at android.app.ActivityThread.main(ActivityThread.java:6661)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1106)
at com.an-droid.internal.os.ZygoteInit.main(ZygoteInit.java:967)
此错误将我带到setImage(imgURLs.get(0), glImageView, mAppend);
,如果其他类似原因,我会尝试将其插入
if (imgURLs.get(0).equals(null)) {
simpleActivity.toastMessage(getActivity(), "There is no image on " + mAppend);
} else {
setImage(imgURLs.get(0), glImageView, mAppend);
}
但是它根本不起作用。它说imgURLs.get(0).equals(null) is always false
,所以..任何人都可以帮助我T?T ??