我有一个从 sqlite 数据库中检索行并在游标中返回它们的方法。我正在从查询中检索值,如下所示。
private void checkWatchList() {
Log.i("watch list", "watch list started");
Cursor cursor = null;
try {
cursor = dbhandler.getAlerts();
while (cursor.moveToNext()) {
Log.i("watch list", "checked");
String share_name = cursor.getString(cursor
.getColumnIndex(KEY_SHARE_NAME));
String max_price = cursor.getString(cursor
.getColumnIndex(KEY_MAX_PRICE));
String min_price = cursor.getString(cursor
.getColumnIndex(KEY_MIN_PRICE));
int action = cursor.getInt(cursor.getColumnIndex(KEY_ACTION));
Log.i("name", share_name + "/" + min_price + "/" + max_price);
if (min_price.equalsIgnoreCase("null")) {
Log.i("min", "msg");
double maxprice = Double.parseDouble(max_price);
compareMax(share_name, maxprice, action);
} else if (max_price.equalsIgnoreCase("null")) {
Log.i("max", "msg");
double minprice = Double.parseDouble(min_price);
compareMin(share_name, minprice, action);
} else {
Log.i("minmax", "msg");
double maxprice = Double.parseDouble(max_price);
double minprice = Double.parseDouble(min_price);
compareMinMax(share_name, minprice, maxprice, action);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
cursor.close();
}
}
问题是
在检查列值时null
。例如对于具有值的行(KEY_SHARE_NAME=name,KEY_MAX_PRICE=12,KEY_MIN_PRICE=null)
,程序会引发一个null pointer exceptiuon at "else if (max_price.equalsIgnoreCase("null"))"
部分。我做错了什么?我似乎无法指出确切的问题。