我正在开发基于位置的提醒应用程序。我尝试使用此代码从数据库中删除行。但它不能正常工作。它显示强制退出错误。所以,如果有人可以提出建议,请发布... 提前谢谢。
用DBAdapter类编写的代码::
public boolean deletesaved_locn(String place1)
{
return db.delete(DATABASE_TABLE, KEY_PLACE + "=" + place1, null) > 0;
}
此代码是在类扩展活动中编写的,其中db是DBAdapter的实例
db.open();
Cursor c = db.getsaved_locn();
if(c.moveToFirst())
{
while(c.isAfterLast()== false)
{
saved_latitude = c.getDouble(1);
saved_longitude = c.getDouble(2);
Location.distanceBetween(saved_latitude, saved_longitude, cur_latitude, cur_longitude, results);
if(results[0] < 50)
{
tv1.setText("Aalo re..."+ c.getString(0)+ " : "+ results[0]);
// mp.start();
if(db.deletesaved_locn(c.getString(0)))
{
Toast.makeText(getBaseContext(), "Delete successful.",
Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getBaseContext(), "Delete failed.",
Toast.LENGTH_LONG).show();
}
}
c.moveToNext();
}
}
else
{
tv1.setText("No rows......");
}
db.close();