Android 更新查询SQLite提供空指针异常

Android 更新查询SQLite提供空指针异常,android,sqlite,sql-update,Android,Sqlite,Sql Update,我使用了db=this.getWritableDatabase();在构造函数本身中,所以我没有使用特定的打开或关闭函数。我应该吗 public void changeCabLocation(String to_loc, String cab_id2) { // TODO Auto-generated method stub ContentValues val=new ContentValues(); val.put(cab_location, to_loc);

我使用了db=this.getWritableDatabase();在构造函数本身中,所以我没有使用特定的打开或关闭函数。我应该吗

public void changeCabLocation(String to_loc, String cab_id2) {
    // TODO Auto-generated method stub
    ContentValues val=new ContentValues();
    val.put(cab_location, to_loc);
    db.update(TB_cabs, val, cab_id+"="+cab_id2, null);
}

public void changeDriverLocation(String to_loc, String driver_id2) {
    // TODO Auto-generated method stub
    ContentValues val=new ContentValues();
    val.put(driver_location, to_loc);
    db.update(TB_drivers, val, driver_id+"="+driver_id2, null);
}
请尝试以下操作:

db.update(TB_cabs, val, "cab_id=?", new String[] {cab_id2});

这是如何修复NPE的?我不确定,这就是我为什么写try的原因。但对我来说,cab_id(和driver_id)包含一个列名和一个列值似乎不是很合理。这是一个错误的假设吗?如果没有logcat,我们就无法清楚什么是空的。所以你可能是正确的,但也可能是错误的。我当然同意。请分享日志,说明你的错误发生的具体行,以及。