I have a method below
public Date getLastPaidInvoiceDate(int id)
{
String selectQuery =" SELECT max(Rental_invoices.enddate) as DD from Rental_invoices "+
" where Rental_invoices._id in(select invoice_id from RentalPayments)"+
" and Rental_invoices.tenancy_id"+"="+ id;
Log.e("sql",selectQuery);
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
Date d=null;
if(c.moveToFirst()){
try {
d= fm.parse(c.getString(c.getColumnIndex("DD")));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return d;
}else
{
return null;
}
}
If i print out the sql string and run it sqlite manager(fire fox), it returns the data i want.
Trying to use it code, i keep getting null pointer exception err as below
12-29 04:30:14.923: W/System.err(2017): java.lang.NullPointerException
12-29 04:30:14.923: W/System.err(2017): at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1009)
12-29 04:30:14.923: W/System.err(2017): at java.text.DateFormat.parse(DateFormat.java:553)
12-29 04:30:14.943: W/System.err(2017): at meter.manager.helper.DatabaseHelperClass.getLastPaidInvoiceDate(DatabaseHelperClass.java:2726)
12-29 04:30:14.943: W/System.err(2017): at com.example.metermanager.SetInActiveTenant.UpDate(SetInActiveTenant.java:79)
12-29 04:30:14.943: W/System.err(2017): at java.lang.reflect.Method.invokeNative(Native Method)
12-29 04:30:14.943: W/System.err(2017): at java.lang.reflect.Method.invoke(Method.java:515)
12-29 04:30:14.943: W/System.err(2017): at android.view.View$1.onClick(View.java:3818)
12-29 04:30:14.943: W/System.err(2017): at android.view.View.performClick(View.java:4438)
12-29 04:30:14.943: W/System.err(2017): at android.view.View$PerformClick.run(View.java:18422)
12-29 04:30:14.943: W/System.err(2017): at android.os.Handler.handleCallback(Handler.java:733)
12-29 04:30:14.943: W/System.err(2017): at android.os.Handler.dispatchMessage(Handler.java:95)
12-29 04:30:14.943: W/System.err(2017): at android.os.Looper.loop(Looper.java:136)
12-29 04:30:14.943: W/System.err(2017): at android.app.ActivityThread.main(ActivityThread.java:5017)
12-29 04:30:14.943: W/System.err(2017): at java.lang.reflect.Method.invokeNative(Native Method)
12-29 04:30:14.943: W/System.err(2017): at java.lang.reflect.Method.invoke(Method.java:515)
12-29 04:30:14.943: W/System.err(2017): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
12-29 04:30:14.943: W/System.err(2017): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
12-29 04:30:14.943: W/System.err(2017): at dalvik.system.NativeStart.main(Native Method)
This is how i use in code
Date d=db.getLastPaidInvoiceDate(id);
Any reason why?
Aucun commentaire:
Enregistrer un commentaire