I have a method which retrieves rows from an sqlite database and returns them in a cursor.I am retreiving values from the query ok as shown below.
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();
}
}
Problem is
when checking column values for null
.For example for a row with values (KEY_SHARE_NAME=name,KEY_MAX_PRICE=12,KEY_MIN_PRICE=null)
,the program raises a null pointer exceptiuon at "else if (max_price.equalsIgnoreCase("null"))"
section.what am i doing wrong?I cant seem to point the exact issue.