0
//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;
        }

我正在尝试从数据库中检索值,但情况是,当我查询数据库时,它总是抛出 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
4

3 回答 3

0

您的查询返回 null,这就是您尝试访问它时的光标。您可能想要添加

cursor != null

访问它之前的条件。

于 2013-10-21T17:08:18.110 回答
0
... from PALM_ORD_DET, PALM_ORDER"
+ " PRODUCT P where ...

这将连接成

... from PALM_ORD_DET, PALM_ORDER PRODUCT P where ...

这是无效的!

你必须选择

... from PALM_ORD_DET, PALM_ORDER PRODUCT where ...

或者

... from PALM_ORD_DET, PALM_ORDER PRODUCT where ...

并相应地使用参考PALM_ORDER

于 2013-10-21T15:58:34.273 回答
0

cursor.close() 不正确,如果要关闭数据库连接使用,则不需要它而不是这个sQLiteDatabase.close();

于 2013-10-21T16:43:00.417 回答