gpt4 book ai didi

android - 游标索引越界

转载 作者:太空狗 更新时间:2023-10-29 16:05:18 26 4
gpt4 key购买 nike

我试图在数据库中搜索 id 是否存在,当它存在时我打开下一个 Activity ,但当它不存在时应用程序崩溃..我找不到错误,错误 Cursor Index out of bound

                 Database dbc = new Database(this);
dbc.open();
String id = searchId.getText().toString();
boolean checkId = dbc.isGotId(id);

if(checkId == true){
String s = searchId.getText().toString();
Bundle b = new Bundle();
b.putString("key",s);
b.putInt("keyX", radioBtnFlag);
Intent a = new Intent(SearchUpdate.this, UpdateDelete.class);
a.putExtras(b);
startActivity(a);

searchId.setText(null);

}else if(checkId == false){

Log.v(id, id + "2222222");

Dialog d = new Dialog(this);
d.setTitle("Error!");
TextView tv = new TextView(this);
tv.setText("This Search is allow only ID! "+ radioBtnFlag);
d.setContentView(tv);
d.show();

searchId.setText(null);

这里...

  public boolean isGotId(String id){

boolean result = false;
try{

Cursor sId = ourDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " + Pro_ID + "=" + id, null);

result = true;
}catch(SQLiteException e)
{
result = false;
}//catch

return result;

}//isGOtId

最佳答案

试试这个...

public boolean isGotId(String id){

Cursor sId = ourDatabase.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE " +
Pro_ID + "=" + id, null);
int numberOfRows = sId.getCount();
if(numberOfRows <= 0)
{
return false;
}

return true;
}

关于android - 游标索引越界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17019902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com