獲取遊標error.i'm新手到android所以需要一個help.cursor顯示索引5請求的CursorIndexOutOfBoundsException的運行時異常,大小爲5. 在這個下面的程序中,我已經實現了AndroidSlidingUpPanel-主。遊標值顯示正確,但當我嘗試向上滾動滑塊然後拋出遊標錯誤。在android的運行時光標錯誤
Context mContext;
Cursor mCursor;
boolean movetonext = false;
private LayoutInflater inflater;
DownloadedFileListAdapter(Context m, Cursor c) {
mContext = m;
mCursor = c;
}
@Override
public int getCount() {
return mCursor.getCount();
}
@Override
public Object getItem(int position) {
return mCursor.moveToNext();
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.display_file_list, null);
TextView fileName = (TextView) convertView.findViewById(R.id.downloaded_file_name);
TextView fileCreatedOn = (TextView) convertView.findViewById(R.id.file_path_created_on);
fileName.setText("" + mCursor.getString(0));
fileCreatedOn.setText("" + mCursor.getString(2));
getItem(position);
return convertView;
}
P.S:
10-01 12:17:26.268: E/AndroidRuntime(22538): android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
10-01 12:17:26.268: E/AndroidRuntime(22538): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)
10-01 12:17:26.268: E/AndroidRuntime(22538): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)
10-01 12:17:26.268: E/AndroidRuntime(22538): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)
10-01 12:17:26.268: E/AndroidRuntime(22538): at com.example.socialapp.DownloadedFileListAdapter.getView(DownloadedFileListAdapter.java:56)
在你的'getItemId'方法除了返回0,返回'position'。 – GrIsHu 2014-10-01 07:00:44
你是否知道[Simple] CursorAdapter? – pskink 2014-10-01 07:07:19
@GrlsHu它仍然顯示相同的問題 – user3721186 2014-10-01 07:27:40