fileManager中的java.lang.IndexOutOfBoundsException
我在文件管理器上工作 我怎样才能解决这个问题 我不明白例外的原因。错误日志如下所示fileManager中的java.lang.IndexOutOfBoundsException,java,android,file-management,Java,Android,File Management,我在文件管理器上工作 我怎样才能解决这个问题 我不明白例外的原因。错误日志如下所示 ERROR/AndroidRuntime(6155): FATAL EXCEPTION: main java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) at java.
ERROR/AndroidRuntime(6155): FATAL EXCEPTION: main
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at com.FileExplorer.FileSystemAdapter.getView(FileSystemAdapter.java:46)
这是我的活动课
下面是BaseAdapter类
public class FileSystemAdapter extends BaseAdapter
{
LayoutInflater inflater;
ArrayList<String> files;
ArrayList<Integer> isFolder;
Context ctx;
public FileSystemAdapter(Context ctx ,ArrayList<String> files,ArrayList<Integer> isFolder)
{
this.files = files;
this.ctx = ctx;
this.isFolder = isFolder;
inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount()
{
return files.size();
}
@Override
public Object getItem(int position)
{
return files.get(position);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View v = inflater.inflate(R.layout.item,parent,false);
ImageView imageFolder = (ImageView)v.findViewById(R.id.imageFolder);
if(isFolder.get(position) == MainActivity.yesFolder)
{
imageFolder.setImageResource(R.drawable.folder);
}
TextView textItem = (TextView)v.findViewById(R.id.textItem);
textItem.setText(files.get(position));
return v;
}
}
由于以下原因,directoryEntries比isFolders多包含1项
directoryEntries.add("..");
哪一个是第46行?我整天都在看代码,不可能看到这个小麻烦,非常感谢。我还有另外一个问题,我如何对directoryEntries进行排序,以避免失去directoryEntries和isFolders之间的界限;对不起,我的英语不好,你可以在getView中有一个isDirectory的文件和测试列表。
directoryEntries.add("..");