dimanche 8 février 2015

Get Values from Sqlite in Android

i need to check if the the entry is add today.only one entry can add per day.



public Cursor getTermValues() {

String from[] = { "_id" };
String where = DBhelper.C_DATE + "=?";
String[] whereArgs = new String[] { formattedDate + "" };
Cursor cursor = db.query(DBhelper.TABLE, from, where, whereArgs, null,
null, null, null);
return cursor;
}


formattedDate is the current date. so to check if there is entry already added i use this in a onclicklistner



if (btnview == v) // button click {

Cursor c1 = getTermValues();
if (c1 != null) {

while(c1.moveToNext()){

String amount = c1.getString(c1.getColumnIndex("amout"));

}
Toast.makeText(this, "amount",
Toast.LENGTH_LONG).show();

} if (c1 == null) {



Toast.makeText(this, "amount",
Toast.LENGTH_LONG).show();




}


}


but i get this error


02-09 11:43:17.291: E/AndroidRuntime(28752): FATAL EXCEPTION: main 02-09 11:43:17.291: E/AndroidRuntime(28752): java.lang.NullPointerException 02-09 11:43:17.291: E/AndroidRuntime(28752): at com.app.Mainclass.getTermValues(Mainclass.java:125) 02-09 11:43:17.291: E/AndroidRuntime(28752): at com.app.Mainclass.onClick(Mainclass.java:92) 02-09 11:43:17.291: E/AndroidRuntime(28752): at android.view.View.performClick(View.java:4101) 02-09 11:43:17.291: E/AndroidRuntime(28752): at android.view.View$PerformClick.run(View.java:17082) 02-09 11:43:17.291: E/AndroidRuntime(28752): at android.os.Handler.handleCallback(Handler.java:615) 02-09 11:43:17.291: E/AndroidRuntime(28752): at android.os.Handler.dispatchMessage(Handler.java:92) 02-09 11:43:17.291: E/AndroidRuntime(28752): at android.os.Looper.loop(Looper.java:137) 02-09 11:43:17.291: E/AndroidRuntime(28752): at android.app.ActivityThread.main(ActivityThread.java:4950) 02-09 11:43:17.291: E/AndroidRuntime(28752): at java.lang.reflect.Method.invokeNative(Native Method) 02-09 11:43:17.291: E/AndroidRuntime(28752): at java.lang.reflect.Method.invoke(Method.java:511) 02-09 11:43:17.291: E/AndroidRuntime(28752): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798) 02-09 11:43:17.291: E/AndroidRuntime(28752): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565) 02-09 11:43:17.291: E/AndroidRuntime(28752): at dalvik.system.NativeStart.main(Native Method)


Aucun commentaire:

Enregistrer un commentaire