我遇到了一个非常奇怪的异常。它在这里运行良好,但我的客户一直遇到这个异常然后崩溃,我花了很多时间才弄清楚,但不幸的是到目前为止仍然没有运气,任何帮助将不胜感激!
这是代码:
protected void onPostExecute(List<File> result) {
try {
mBooks.clear();
if (result != null) {
ArrayList<BookInfo> newBooks = new ArrayList<BookInfo>();
for (File f : result) {
BookInfo bi = new BookInfo(BookCollections.this, f);
if (!contains(bi)) {
newBooks.add(bi);
}
}
mDB.insertBooks(newBooks);
mBooks.addAll(newBooks);
new AlertDialog.Builder(BookCollections.this)
.setTitle(newBooks.size() + " Books found!")
.setPositiveButton(android.R.string.ok, null)
.setView(
new BookInfoList(BookCollections.this,
newBooks)).show();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
mScanDlg.dismiss();
notifyDataSetChanged();
}
}
private boolean contains(BookInfo bi) {
if (bi == null) {
return true;
}
for (BookInfo book : mBooks) {
if (book.equalTo(bi)) {
return true;
}
}
for (FolderInfo fi : mFolders) {
if (fi.getBooks() != null) {
for (BookInfo book : fi.getBooks()) {
if (book.equalTo(bi)) {
return true;
}
}
}
}
return false;
}
请帮我。谢谢
这个异常(java.lang.ArrayIndexOutOfBoundsException)在
for (File f : result) {
BookInfo bi = new BookInfo(BookCollections.this, f);
if (!contains(bi)) {
newBooks.add(bi);
}
}