运行我的代码时,我得到了这个 CursorWindowAllocationException:
代码:
try{
Uri uri;
uri = RawContactsEntity.CONTENT_URI;
final String selection = Data.CONTACT_ID + "=?";
final String[] selectionArgs = new String[] { contactId.id };
cur = _resolver.query(uri, null, selection, selectionArgs, null);
if (cur == null)
return null;
if (cur.moveToFirst() == false)
{
cur.close();
return null;
}
entityIterator = RawContacts.newEntityIterator(cur);
if (entityIterator == null)
{
Logger.error(TAG, "EntityIterator is null");
return null;
}
while (entityIterator.hasNext())
{
Entity entity = entityIterator.next();
for (NamedContentValues namedContentValues : entity
.getSubValues())
{
ContentValues contentValues = namedContentValues.values;
String key = contentValues.getAsString(Data.MIMETYPE);
if (key != null)
{
contentValuesList.add(contentValues);
}
}
}
}
finally
{
if (cur != null)
{
cur.close();
}
if (entityIterator != null)
{
entityIterator.close();
}
}
但有时我会得到这个例外:
android.database.CursorWindowAllocationException: Cursor window could not be created from binder.
at android.database.CursorWindow.<init>(CursorWindow.java:141)
at android.database.CursorWindow.<init>(CursorWindow.java:41)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:697)
at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:695)
at android.database.CursorWindow.newFromParcel(CursorWindow.java:706)
at android.database.BulkCursorProxy.getWindow(BulkCursorNative.java:196)
at android.database.BulkCursorToCursorAdaptor.onMove(BulkCursorToCursorAdaptor.java:94)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:178)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:201)
at android.database.CursorWrapper.moveToFirst(CursorWrapper.java:65)
at android.content.CursorEntityIterator.<init>(CursorEntityIterator.java:39)
at android.provider.ContactsContract$RawContacts$EntityIteratorImpl.<init>(ContactsContract.java:2844)
at android.provider.ContactsContract$RawContacts.newEntityIterator(ContactsContract.java:2818)
at com.wangma.wubi.datasource.device.contact.ContactDeviceDataSource.loadOneContact(ContactDeviceDataSource.java:156)
at com.wangma.wubi.services.upload.grammar.content.ContactList$1.getNext(ContactList.java:73)
at com.wangma.wubi.services.upload.grammar.content.UriWordListBase$PlatformFullIterator.hasNext(UriWordListBase.java:60)
at com.wangma.wubi.services.upload.grammar.content.WordListBase.findChangeList(WordListBase.java:530)
at com.wangma.wubi.services.upload.grammar.content.WordListBase.platformFullUpdate(WordListBase.java:454)
at com.wangma.wubi.services.upload.grammar.content.WordListBase.goPlatformFullUpdate(WordListBase.java:437)
at com.wangma.wubi.services.upload.grammar.content.WordListBase.access$1200(WordListBase.java:38)
at com.wangma.wubi.services.upload.grammar.content.WordListBase$1.update(WordListBase.java:422)
at com.wangma.wubi.services.upload.grammar.content.WordListBase$PendingFullUpdate$1.run(WordListBase.java:174)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at com.nuance.balerion.services.jobs.LooperJob$LooperStarter.run(LooperJob.java:74)
at java.lang.Thread.run(Thread.java:856)
虽然这种崩溃并不容易重现,但它确实偶尔会发生。有谁知道为什么会发生这种情况?