Java 为什么我的代码会出现这样的错误?CursorIndexOutOfBoundsException
有没有人能找到我代码中的错误?我已经尝试了很多东西,但总是以同样的错误告终 这是我的代码:Java 为什么我的代码会出现这样的错误?CursorIndexOutOfBoundsException,java,android,cursor,indexoutofboundsexception,toast,Java,Android,Cursor,Indexoutofboundsexception,Toast,有没有人能找到我代码中的错误?我已经尝试了很多东西,但总是以同样的错误告终 这是我的代码: String signeedep = spn.getSelectedItem().toString(); int a = spn1.getSelectedItemPosition(); Cursor userid = db.getallsigneenumber(); u
String signeedep = spn.getSelectedItem().toString();
int a = spn1.getSelectedItemPosition();
Cursor userid = db.getallsigneenumber();
userid.moveToPosition(a);
Toast.makeText(getApplicationContext(),
userid.getString(1) + "//this is where the error points out
was assigned to the " + signeedep + ".",Toast.LENGTH_SHORT).show();
userid.close();
/*
db.open();
db.insertAssignsignee(signeedep, userid.getString(0));
db.close();
*/
myMethod();
这是我的错误:
FATAL EXCEPTION: main
android.database.CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1
可能您应该首先使用
String userIdString=userid.toString代码>
如果可能的话
然后可以使用userIdString.substring(1,2)编码>首先确保您的光标不为空,并且其中包含所需数量的元素
记住moveToPosition(1)返回第二行,因为它是零索引的调用getString(1)你想做什么?我想得到第1列中的值,它是id。@Justine你的表包含两列还是单列?我加入了两个表,它们总共有7列。也许这可以帮助你:谢谢!我在int变量上加了-1,结果成功了。