plz help me i face this problem
my code is
`final Cursor curr = dbhelper.getdatatomanagedata();
startManagingCursor(curr);
Integer colid = curr.getInt(0);
String colans = curr.getString(1);
objansMap = new HashMap<Integer, String>();
if (curr!=null)
{
curr.moveToFirst();
while(!curr.isAfterLast())
{
objansMap.put(colid, colans);
curr.moveT开发者_开发技巧oNext();
}}
Your code must be as
final Cursor curr = dbhelper.getdatatomanagedata();
startManagingCursor(curr);
Integer colid;
String colans;
objansMap = new HashMap<Integer, String>();
if (curr!=null)
{
curr.moveToFirst();
while(!curr.isAfterLast())
{ colid = curr.getInt(0);
colans = curr.getString(1);
objansMap.put(colid, colans);
curr.moveToNext();
}}
When cursor returns its default index is -1, and you must move to its 0th index by using moveToFirst()
.
Another way to use your code as
if(cur.moveToFirst()){
do{
//YOUR CODE HERE
objansMap.put(curr.getInt(0), curr.getString(1));
}while(cur.moveToNext());
}
Happy coding :)
精彩评论