i’m making a chart which contain x and y value from sqlite.
my code is like this :
Double a, b;
notesCursor.moveToFirst();
do {
a = notesCursor.getDouble(notesCursor.getColumnIndex(DbAdapter.KEY_ROWID));
b = notesCursor.getDouble(notesCursor.getColumnIndex(DbAdapter.KEY_RESULT));
mCurrentSeries.add(a, b);
}while(notesCursor.moveToNext());
when i didn’t insert any x y value to my sqlite, the errors message came out… i want to add some code which when even i didn’t insert any x y value to my database, the chart will come out with 0, 0 value..
i’ve been making a code like this :
Double a, b;
if(a==null && b==null){
mCurrentSeries.add(0.0, 0.0);
}
else{
notesCursor.moveToFirst();
do {
a = notesCursor.getDouble(notesCursor.getColumnIndex(DbAdapter.KEY_ROWID));
b = notesCursor.getDouble(notesCursor.getColumnIndex(DbAdapter.KEY_RESULT));
mCurrentSeries.add(a, b);
}while(notesCursor.moveToNext());
}
but i can’t make it work, anyone can help me to solve this problem? thank you
Your new code does not guarantee that a and b will be not null when passed to the mCurrentSeries.add method:
import java.util.Map;
public class C {
Double a, b;
Map mCurrentSeries = new HashMap();
NotesCursor notesCursor = new NotesCursor();
}