//this is in my custom dialog class oncreate method
InvoiceDatabase invoiceDatabase = new InvoiceDatabase(context);
TotalInvoiceVO totalInvoiceVo = invoiceDatabase.getPrintInvoiceDetails(custCode);
invoiceDetails.setText(totalInvoiceVo.toString());
//this is my InvoiceDatabase class
public static String GET_INVOICEDETAILS = "select P.ProductCode productCode, P.MRP mrp, P.SellingRate sellingRate, P.ShortProductDesc desc, P.Vat vat, " +
" P.AdditionalTaxes additionalVat,"
+ " P.Cess cess, PalmOrderNo palmOrderNum, "
+ " SaleQty saleQty, DiscAmount stkDiscount ,SchemeAmount schemeAmount, SchemeDisc schemeDiscount, NetValue netValue from PALM_ORD_DET, PALM_ORDER"
+ " PRODUCT P where PALM_ORD_DET.ProductCode=PRODUCT.ProductCode and PALM_ORD_DET.PalmOrderNo=PALM_ORDER.PalmOrderNo and PALM_ORDER.CustCode=?";
public TotalInvoiceVO getPrintInvoiceDetails(String custCode) {
TotalInvoiceVO totalInvoiceVO = new TotalInvoiceVO();
// getStockiest Detail
// get Customer Detail
// get CustomerSummary
List<InvoiceVO> listOfProductInvoice = getProdOrderInvoiceDetails(custCode);
totalInvoiceVO.setListOfProductInvoice(listOfProductInvoice);
return totalInvoiceVO;
}
private List<InvoiceVO> getProdOrderInvoiceDetails(String custCode) {
List<InvoiceVO> listOfInvoiceVO = new ArrayList<InvoiceVO>();
Cursor cursor = null;
try {
/*cursor=db.rawQuery("select * from PALM_ORD_DET", null);
if(cursor.moveToFirst())
{
String m="m";
}*/
cursor = db.rawQuery(GET_INVOICEDETAILS, new String[] { custCode });
if (cursor.moveToFirst()) {
do {
InvoiceVO invoiceVO = new InvoiceVO();
invoiceVO.setProdDesc(cursor.getString(cursor.getColumnIndex("desc")));
invoiceVO.setProdCode(cursor.getString(cursor.getColumnIndex("productCode")));
invoiceVO.setMrp(cursor.getDouble(cursor.getColumnIndex("mrp")));
invoiceVO.setSellingPrice(cursor.getDouble(cursor.getColumnIndex("sellingRate")));
invoiceVO.setNetValue(cursor.getDouble(cursor.getColumnIndex("netValue")));
invoiceVO.setStockDiscount(cursor.getString(cursor.getColumnIndex("stkDiscount")));
listOfInvoiceVO.add(invoiceVO);
} while (cursor.moveToNext());
}
} finally {
cursor.close();
cursor=null;
}
我是一個新的Android和我試圖從數據庫中檢索值,但情況是,當我查詢數據庫,它總是拋出NullPointerException異常。任何人都可能指出什麼可能是錯的?Sqllite總是引發NullPointerException異常
10-21 20:40:24.098: E/AndroidRuntime(27346): FATAL EXCEPTION: main
10-21 20:40:24.098: E/AndroidRuntime(27346): java.lang.NullPointerException
10-21 20:40:24.098: E/AndroidRuntime(27346): at comColgateDMS.org.db.InvoiceDatabase.getProdOrderInvoiceDetails(InvoiceDatabase.java:97)
10-21 20:40:24.098: E/AndroidRuntime(27346): at comColgateDMS.org.db.InvoiceDatabase.getPrintInvoiceDetails(InvoiceDatabase.java:66)
10-21 20:40:24.098: E/AndroidRuntime(27346): at comColgateDMS.org.CustomDialog_invoicePrint.onCreate(CustomDialog_invoicePrint.java:46)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.app.Dialog.dispatchOnCreate(Dialog.java:353)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.app.Dialog.show(Dialog.java:257)
10-21 20:40:24.098: E/AndroidRuntime(27346): at comColgateDMS.org.OrderBookingSummary$1.onItemClick(OrderBookingSummary.java:214)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.widget.AdapterView.performItemClick(AdapterView.java:292)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.widget.AbsListView.performItemClick(AbsListView.java:1065)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2522)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.widget.AbsListView$1.run(AbsListView.java:3183)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.os.Handler.handleCallback(Handler.java:605)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.os.Handler.dispatchMessage(Handler.java:92)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.os.Looper.loop(Looper.java:137)
10-21 20:40:24.098: E/AndroidRuntime(27346): at android.app.ActivityThread.main(ActivityThread.java:4441)
10-21 20:40:24.098: E/AndroidRuntime(27346): at java.lang.reflect.Method.invokeNative(Native Method)
10-21 20:40:24.098: E/AndroidRuntime(27346): at java.lang.reflect.Method.invoke(Method.java:511)
10-21 20:40:24.098: E/AndroidRuntime(27346): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-21 20:40:24.098: E/AndroidRuntime(27346): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-21 20:40:24.098: E/AndroidRuntime(27346): at dalvik.system.NativeStart.main(Native Method)
10-21 20:40:25.878: I/Process(27346): Sending signal. PID: 27346 SIG: 9
請發佈堆棧跟蹤 –
哪一行是#97? – Asahi
cursor.close(); – Sunny