简体   繁体   English

Android SQLite SELECT语句未执行

[英]Android SQLite SELECT statement not executing

I'm building an SQLite database to manage orders, order items and customer datas on an Android device. 我正在建立一个SQLite数据库来管理Android设备上的订单,订单项和客户数据。 I have implemented the DataHelper with SQLiteOpen helper as a private class inside DataAdapter.java and have been able to insert data into the database. 我已经在DataAdapter.java中将SQLHelpOpen帮助程序作为私有类实现了DataHelper,并且能够将数据插入数据库中。

However when I run a simple select _id, order_id, retailer, qty from the_order the code throws and exception. 但是,当我select _id, order_id, retailer, qty from the_order运行一个简单的select _id, order_id, retailer, qty from the_order ,代码将抛出异常。 When I look at the last SQL Statement it seems the select is not executed. 当我查看最后一个SQL语句时,似乎未执行select

Here is the code for the DataAdapter.java, the getAllOrders method has the select statement. 这是DataAdapter.java的代码, getAllOrders方法具有select语句。

package com.orderdelivery;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DataAdapter {

private DataHelper dHelper;
private Context context;
private SQLiteDatabase db;
public static final String ORDER_TABLE_NAME ="the_order";
 public static final String ITEM_TABLE_NAME="item";
 public static final String CUSTOMER_TABLE_NAME="customer";
 public static final String CUSTOMER_KEY_ID="_id";
public static final String CUSTOMER_KEY_ORDER_ID = "order_id";
public static final String CUSTOMER_KEY_NAME = "name";
public static final String CUSTOMER_KEY_ADDRESS = "address";
public static final String CUSTOMER_KEY_COUNTRY = "country";
public static final String CUSTOMER_KEY_ZIPCODE = "zip_code";
public static final String CUSTOMER_KEY_CITY = "city";
public static final String CUSTOMER_KEY_HOMEPHONE = "home_phone";
public static final String CUSTOMER_KEY_CELLPHONE = "cell_phone"; 
public static final String ITEM_KEY_NAME="name";
public static final String ITEM_KEY_ID="item_id";
public static final String ITEM_KEY_ORDER_ID="order_id";
public static final String ITEM_KEY_DESCRIPTION="description";
public static final String ITEM_KEY_QTY="qty";
public static final String ITEM_KEY_BRAND="brand";
public static final String ITEM_KEY_CURRENTQTY="current_qty";
public static final String ITEM_KEY_ITEM_ID_INC="_id";
public static final String ITEM_KEY_PRICE="price";
public static final String ITEM_KEY_BARCODE="barcode";
public static final String ORDER_KEY_ORDER_ID = "order_id";
public static final String ORDER_KEY_ORDER_IDSQLITE="_id";
public static final String ORDER_KEY_STATUS="status";
public static final String ORDER_KEY_CONFIRMATIONCODE="confirmation_code";
public static final String ORDER_KEY_HOUR = "hour";
public static final String ORDER_KEY_MINUTE="minute";
public static final String ORDER_KEY_RETAILER="retailer_name";
public static final String ORDER_KEY_RETAILERADDRESS="retailer_address";
public static final String ORDER_KEY_QTY="qty";
private static final String DATABASE_NAME = "orderdata.db";
private static final int    DATABASE_VERSION =1;
private static final String ORDER_TABLE_CREATE = "create table the_order(order_id text not null, qty integer not null," 
                                                + " status text not null, confirmation_code text not null, hour integer not null," 
                                                + " minute integer not null, retailer_name text not null, retailer_address text not null, _id integer primary key autoincrement, unique(order_id));";
private static final String CUSTOMER_TABLE_CREATE= "create table customer(order_id text not null, name text not null, "
                                                  +"address text not null, country text not null,city text not null,zip_code text not null, "
                                                  +"home_phone text not null, cell_phone text not null, _id integer primary key autoincrement, foreign key(order_id) references the_order(order_id));";
private static final String ITEMS_TABLE_CREATE="create table item(order_id text not null, name text not null, "
                                              +"description text not null, qty integer not null, brand text not null, current_qty integer not null, price real not null, "
                                              +"item_id integer not null , barcode text, _id integer primary key autoincrement, foreign key(order_id) references the_order(order_id));";




public DataAdapter(Context context) {

    this.context = context;
}

public DataAdapter open() throws SQLException{

    //For testing
//      db.delete(this.ORDER_TABLE_NAME, null, null);
//      db.delete(this.ITEM_TABLE_NAME, null, null);
//      db.delete(this.CUSTOMER_TABLE_NAME, null, null);

    //Actual code
    dHelper = new DataHelper(context);
    db = dHelper.getWritableDatabase();
    boolean test = db.isOpen();
    test = db.isReadOnly();
    test = db.isDbLockedByCurrentThread();
    return this;
}

public void close(){
    dHelper.close();
    db.close();

}

public long addOrder(String id, String status, String confirmationCode, int hour,        int minute, String retailer, String retailerAddress, int qty){

    ContentValues values = new ContentValues();
    values.put(this.ORDER_KEY_ORDER_ID, id);
    values.put(this.ORDER_KEY_STATUS,status);
    values.put(this.ORDER_KEY_CONFIRMATIONCODE,confirmationCode);
    values.put(this.ORDER_KEY_HOUR, hour);
    values.put(this.ORDER_KEY_MINUTE,minute);
    values.put(this.ORDER_KEY_RETAILER, retailer);
    values.put(this.ORDER_KEY_RETAILERADDRESS,retailerAddress);
    values.put(this.ORDER_KEY_QTY,qty);

    return db.insert(this.ORDER_TABLE_NAME, null, values);



}

public long addItem(String id, String name, String orderId, String description, int  qty, String brand, int currentQty ,double price, String barcode){

    ContentValues values = new ContentValues();
    values.put(this.ITEM_KEY_NAME, name);
    values.put(this.ITEM_KEY_ORDER_ID, orderId);
    values.put(this.ITEM_KEY_DESCRIPTION, description);
    values.put(this.ITEM_KEY_QTY, qty);
    values.put(this.ITEM_KEY_BRAND, brand);
    values.put(this.ITEM_KEY_CURRENTQTY, currentQty);
    values.put(this.ITEM_KEY_PRICE, price);
    values.put(this.ITEM_KEY_ID, id);
    values.put(this.ITEM_KEY_BARCODE, barcode);

    return db.insert(this.ITEM_TABLE_NAME, null, values);   
}

public long addCustomer(String orderId, String name,String address, String country, String city ,String zipCode, String homePhone, String cellPhone){

    ContentValues values = new ContentValues();
    values.put(this.CUSTOMER_KEY_ORDER_ID, orderId);
    values.put(this.CUSTOMER_KEY_NAME, name);
    values.put(this.CUSTOMER_KEY_ADDRESS, address);
    values.put(this.CUSTOMER_KEY_COUNTRY, country);
    values.put(this.CUSTOMER_KEY_CITY, city);
    values.put(this.CUSTOMER_KEY_ZIPCODE, zipCode);
    values.put(this.CUSTOMER_KEY_HOMEPHONE,homePhone);
    values.put(this.CUSTOMER_KEY_CELLPHONE,cellPhone);


    return db.insert(this.CUSTOMER_TABLE_NAME, null, values);   
}

public int changeOrderStatus(String orderId, String status){

    ContentValues values = new ContentValues();
    values.put(ORDER_KEY_STATUS, status);
    return db.update(ORDER_TABLE_NAME, values, this.ORDER_KEY_ORDER_ID+"=?", new String[]{orderId});
}

public int changeItemCurrentQty(String orderId, String itemId, int currentQty){

    ContentValues values = new ContentValues();
    values.put(this.ITEM_KEY_CURRENTQTY, currentQty);


    return db.update(ITEM_TABLE_NAME, values, this.ITEM_KEY_ORDER_ID+"="+orderId+" and "+this.ITEM_KEY_ID+"="+itemId, null);
}

public int changeItemTotalQuantity(String orderId, String itemId, int qty){

    ContentValues values = new ContentValues();
    values.put(this.ITEM_KEY_QTY, qty);

    return db.update(this.ITEM_KEY_QTY,values,this.ITEM_KEY_ORDER_ID+"="+orderId+" and "+this.ITEM_KEY_ID+"="+itemId,null);
}

public Cursor getAllOrders(){

//      Cursor cursor = db.query(this.ORDER_TABLE_NAME, 
    //              new String[]{this.ORDER_KEY_ORDER_IDSQLITE,         this.ORDER_KEY_ORDER_ID, this.ORDER_KEY_RETAILER, this.ORDER_KEY_QTY, this.ORDER_KEY_STATUS         },
    //              null, 
    //              new String[]{}, 
    //              null,
    //              null,
    //              this.ORDER_KEY_ORDER_IDSQLITE);
        String query = "select "+this.ORDER_KEY_ORDER_IDSQLITE +",         "+this.ORDER_KEY_RETAILER+", "+this.ORDER_KEY_QTY+", "+this.ORDER_KEY_ORDER_ID+",         "+this.ORDER_KEY_STATUS+ " from the_order;";

        Cursor c = db.rawQuery(query, null);

        return c;

    }

    public void deleteAll(){

        db.delete(ORDER_TABLE_NAME, null, null);
        db.delete(ITEM_TABLE_NAME, null, null);
    db.delete(CUSTOMER_TABLE_NAME,null,null);
}

    public Cursor getAllItems(String orderId){

        Cursor c = db.query(this.ITEM_TABLE_NAME, new String[]    {this.ITEM_KEY_ITEM_ID_INC,     this.ITEM_KEY_NAME,this.ITEM_KEY_BRAND,this.ITEM_KEY_CURRENTQTY,this.ITEM_KEY_QTY},     this.ITEM_KEY_ORDER_ID+"=?", new String[]{orderId}, null, null, this.ITEM_KEY_ITEM_ID_INC);

    return c;
}

public Cursor getItemForList(String orderId, String itemId){

        Cursor c = db.query(this.ITEM_TABLE_NAME, new String[]    {this.ITEM_KEY_ITEM_ID_INC,this.ITEM_KEY_NAME,this.ITEM_KEY_BRAND,this.ITEM_KEY_CURRENTQTY,  this.ITEM_KEY_QTY}, this.ITEM_KEY_ORDER_ID+"=? and "+ this.ITEM_KEY_ID+" =?", new String[]     {orderId,itemId}, null, null, null);

    return c;
}

    public ArrayList<String> getItemDetails(String orderId, String itemId){
        Cursor c = db. query(this.ITEM_TABLE_NAME, new String[]      {this.ITEM_KEY_ITEM_ID_INC,this.ITEM_KEY_NAME,this.ITEM_KEY_BRAND,     this.ITEM_KEY_CURRENTQTY,this.ITEM_KEY_QTY,this.ITEM_KEY_PRICE,this.ITEM_KEY_DESCRIPTION},     this.ITEM_KEY_ID+" =? and "+ this.ITEM_KEY_ORDER_ID +" =?", new String[]{itemId,     orderId},null,null,null);
    //TODO
    c.moveToFirst();

    ArrayList<String> data = new ArrayList<String>();
    data.add(c.getString(c.getColumnIndex(this.ITEM_KEY_NAME)));
    data.add(c.getString(c.getColumnIndex(this.ITEM_KEY_BRAND)));
    data.add(((Double)     c.getDouble(c.getColumnIndex(this.ITEM_KEY_DESCRIPTION))).toString());
    data.add(c.getString(c.getColumnIndex(this.ITEM_KEY_CURRENTQTY)));
    data.add(c.getString(c.getColumnIndex(this.ITEM_KEY_QTY)));

    return data;
}

public ArrayList<String> getOrderDetails(String orderId){

    Cursor cursorOrder = db.query(this.ORDER_TABLE_NAME, new String[]   {this.ORDER_KEY_ORDER_IDSQLITE,     this.ORDER_KEY_STATUS,this.ORDER_KEY_RETAILER,this.ORDER_KEY_STATUS,this.ORDER_KEY_HOUR,thi  s.ORDER_KEY_MINUTE}, this.ORDER_KEY_ORDER_ID+" =?", new String[]{orderId}, null, null,     null);
        Cursor cursorCustomer = db.query(this.CUSTOMER_TABLE_NAME, new String[]    {this.CUSTOMER_KEY_ID,     this.CUSTOMER_KEY_NAME,this.CUSTOMER_KEY_ADDRESS,this.CUSTOMER_KEY_CITY,this.CUSTOMER_KEY_C  OUNTRY,this.CUSTOMER_KEY_ZIPCODE,this.CUSTOMER_KEY_CELLPHONE,this.CUSTOMER_KEY_HOMEPHONE},     this.CUSTOMER_KEY_ORDER_ID+" =?", new String[]{orderId}, null, null, null);

    cursorOrder.moveToFirst();
    cursorCustomer.moveToFirst();

    ArrayList<String> data = new ArrayList<String>();
    data.add(orderId);
         data.add(cursorOrder.getString(cursorOrder.getColumnIndex(this.ORDER_KEY_STATUS)));
         data.add(cursorOrder.getString(cursorOrder.getColumnIndex(this.ORDER_KEY_RETAILER)));

    //concat dateHour
    String date =     cursorOrder.getString(cursorOrder.getColumnIndex(this.ORDER_KEY_HOUR))+":"+cursorOrder.getS  tring(cursorOrder.getColumnIndex(this.ORDER_KEY_MINUTE));

        data.add(cursorCustomer.getString(cursorCustomer.getColumnIndex(this.CUSTOMER_KEY_NAME)));
        data.add(cursorCustomer.getString(cursorCustomer.getColumnIndex(this.CUSTOMER_KEY_ADDRESS)));
        data.add(cursorCustomer.getString(cursorCustomer.getColumnIndex(this.CUSTOMER_KEY_CITY)));
        data.add(cursorCustomer.getString(cursorCustomer.getColumnIndex(this.CUSTOMER_KEY_COUNTRY))  );
        data.add(cursorCustomer.getString(cursorCustomer.getColumnIndex(this.CUSTOMER_KEY_ZIPCODE)));
        data.add(cursorCustomer.getString(cursorCustomer.getColumnIndex(this.CUSTOMER_KEY_CELLPHONE)));
               data.add(cursorCustomer.getString(cursorCustomer.getColumnIndex(this.CUSTOMER_KEY_HOMEPHONE)));

        return data;
}

private class DataHelper extends SQLiteOpenHelper {





    public DataHelper(Context context){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase arg0) {

        arg0.execSQL(ORDER_TABLE_CREATE);
        arg0.execSQL(ITEMS_TABLE_CREATE);
        arg0.execSQL(CUSTOMER_TABLE_CREATE);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        Log.w("Orders","Upgrading database, this will drop tables and recreate.");
        //drop tables!!! TODO AS SOON AS BACK FROM LUNCH!!
        db.execSQL("drop table if exists "+ITEM_TABLE_NAME);
        db.execSQL("drop table if exists "+ORDER_TABLE_CREATE);
        db.execSQL("drop table if exists "+CUSTOMER_TABLE_NAME);
    }

}
}

This is the OrderList.Java in which I call the getAllOrders method on the OnCreate : 这是OrderList.Java,在其中我在OnCreate上调用getAllOrders方法:

package com.orderdelivery;


import java.util.ArrayList;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView; 
import com.orderdelivery.DataAdapter;

public class OrderList extends ListActivity {

ArrayList<Order> orders;
OrderListAdapter oAdapter;
SimpleOrderAdapter oCursorAdapter;
static Order active = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {



    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ListView list = getListView();
  //  list.setAdapter(oCursorAdapter);
       list.setOnItemClickListener(new OnItemClickListener(){

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {


            startActivity(new    Intent("com.orderdelivery.GROCERYITEMLIST"));
            // TODO Auto-generated method stub
        }



       });

 //        orders = new ArrayList<Order>();
 //        
 //        for(int i =0; i<5;i++){
 //         orders.add(new Order("19995","Pueblo, Maya",i,"Pending", null, null,       null)); //Customer, items, confirmation...
 //        }
 //        
 //        oAdapter = new OrderListAdapter(this,R.layout.row,orders);
 //        list.setAdapter(oAdapter);
 //       
         DataAdapter dbAdapter = new DataAdapter(this);
         dbAdapter.open();

       dbAdapter.deleteAll();
       dbAdapter.addOrder("1995", "Pending", "100101", 12, 31, "Pueblo,Xtra",    "Mayaguez" , 1);
       dbAdapter.addCustomer("1995", "Robert Soler", "Urb. Villa Mofongo II3", "PR",    "Mayaguez", "00617", "787-391-5555", "787-391-5555");
       dbAdapter.addItem("0101", "Habichuelas Blancas", "1995", "Si es GOYA tiene que    ser bueno", 1, "Goya", 0, 2.75, "1001019");

    Cursor oCursor = dbAdapter.getAllOrders();
    oCursorAdapter = new SimpleOrderAdapter(this,R.layout.row,oCursor,null,null);

    list.setAdapter(oCursorAdapter);


}

public static Order getCurrentActiveOrder()
{
    return active;
}

public void setCurrentActiveOrder(Order o){
    active = o;
}

private class OrderListAdapter extends ArrayAdapter<Order> {

    private ArrayList<Order> orders;

    private OrderListAdapter(Context context, int textViewResourceId, ArrayList<Order>    orders)
    {
        super(context, textViewResourceId, orders);
        this.orders = orders;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View v = convertView;
        if (v==null)
        {
            LayoutInflater vi = (LayoutInflater)    getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }

        Order o = orders.get(position);
        if(o!=null){

            TextView orderNum = (TextView) v.findViewById(R.id.orderNumber);
            TextView location = (TextView) v.findViewById(R.id.location);
            TextView quantity = (TextView) v.findViewById(R.id.quantity);
            TextView status = (TextView) v.findViewById(R.id.status);

            if(orderNum!=null){
                orderNum.setText("Order " + o.getOrderNumber());

            }

            if(location!=null)
            {
                location.setText("Location: "+o.getOrderRetailer());
            }

            if(quantity!=null){
                quantity.setText("Qty: "+o.getTotalQuantity());

            }

            if(status!=null){
                status.setText("Status: "+ o.getStatus());
            }

        }

        return v;
    }
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);

    Intent intent = new Intent("com.orderdelivery.GROCERYITEMLIST");

    Bundle bundle = new Bundle();

    bundle.putInt("position", position);


}

//Might be needed
public static Order getOrderAtPosition(int pos){

    return null;

}


private class SimpleOrderAdapter extends SimpleCursorAdapter {

    private LayoutInflater inflater;

    public SimpleOrderAdapter(Context context, int layout, Cursor c,
            String[] from, int[] to) {
        super(context, layout, c, from, to);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void bindView(View v, Context context, Cursor c) {
        // TODO Auto-generated method stub
        super.bindView(v, context, c);
        TextView orderNum = (TextView) v.findViewById(R.id.orderNumber);
        TextView location = (TextView) v.findViewById(R.id.location);
        TextView quantity = (TextView) v.findViewById(R.id.quantity);
        TextView status = (TextView) v.findViewById(R.id.status);

        String orderNumString="Order "+    c.getString(c.getColumnIndex(DataAdapter.ORDER_KEY_ORDER_ID));
        String    locationString=c.getString(c.getColumnIndex(DataAdapter.ORDER_KEY_RETAILER));
        int qty = c.getInt(c.getColumnIndex(DataAdapter.ORDER_KEY_QTY));

        String statusString =    c.getString(c.getColumnIndex(DataAdapter.ORDER_KEY_STATUS));

        orderNum.setText(orderNumString);
        location.setText(locationString);
        quantity.setText(""+qty); //FIXXX
        status.setText(statusString);
    }

    @Override
    public View newView(Context context, Cursor c, ViewGroup parent) {
        // TODO Auto-generated method stub

        final LayoutInflater inflater = LayoutInflater.from(context);

        View v = inflater.inflate(R.layout.row, parent, false);


        TextView orderNum = (TextView) v.findViewById(R.id.orderNumber);
        TextView location = (TextView) v.findViewById(R.id.location);
        TextView quantity = (TextView) v.findViewById(R.id.quantity);
        TextView status = (TextView) v.findViewById(R.id.status);

        String orderNumString="Order "+ c.getString(c.getColumnIndex(DataAdapter.ORDER_KEY_ORDER_ID));
        String locationString="Location: "+c.getString(c.getColumnIndex(DataAdapter.ORDER_KEY_RETAILER));
        String qtyString ="Qty: "+ c.getString(c.getColumnIndex(DataAdapter.ORDER_KEY_QTY));
        String statusString = c.getString(c.getColumnIndex(DataAdapter.ORDER_KEY_STATUS));

        orderNum.setText(orderNumString);
        location.setText(locationString);
        quantity.setText(qtyString);
        status.setText(statusString);
        return v;



        }




}

} }

This is my first post on the site so thanks to anyone who can help :) 这是我在该网站上的第一篇文章,非常感谢可以帮助您的人:)

'Edit' This is the logcat file output: '编辑'这是logcat文件的输出:

D/AndroidRuntime( 7415): CheckJNI is ON

D/AndroidRuntime( 7415): --- registering native functions ---

I/ActivityManager(   58): Starting activity: Intent { act=android.intent.action.MAIN     cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.orderdelivery/.OrderList }

I/ActivityManager(   58): Start proc com.orderdelivery for activity     com.orderdelivery/.OrderList: pid=7421 uid=10033 gids={1015}

D/AndroidRuntime( 7415): Shutting down VM

I/AndroidRuntime( 7415): NOTE: attach of thread 'Binder Thread #3' failed

D/dalvikvm( 7415): Debugger has detached; object registry had 1 entries

I/ARMAssembler(   58): generated scanline__00000077:03545404_00000004_00000000 [ 47   ipp] (67 ins) at [0x2ec420:0x2ec52c] in 1155044 ns

D/AndroidRuntime( 7421): Shutting down VM

W/dalvikvm( 7421): threadid=1: thread exiting with uncaught exception     (group=0x4001d800)

E/AndroidRuntime( 7421): FATAL EXCEPTION: main

E/AndroidRuntime( 7421): java.lang.RuntimeException: Unable to start activity      ComponentInfo{com.orderdelivery/com.orderdelivery.OrderList}:     java.lang.NullPointerException

E/AndroidRuntime( 7421):    at     android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)

E/AndroidRuntime( 7421):    at     android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)

E/AndroidRuntime( 7421):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)

E/AndroidRuntime( 7421):    at     android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)

E/AndroidRuntime( 7421):    at android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidRuntime( 7421):    at android.os.Looper.loop(Looper.java:123)

E/AndroidRuntime( 7421):    at     android.app.ActivityThread.main(ActivityThread.java:4627)

E/AndroidRuntime( 7421):    at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime( 7421):    at java.lang.reflect.Method.invoke(Method.java:521)

E/AndroidRuntime( 7421):    at     com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

E/AndroidRuntime( 7421):    at    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

E/AndroidRuntime( 7421):    at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime( 7421): Caused by: java.lang.NullPointerException

E/AndroidRuntime( 7421):    at     android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:307)

E/AndroidRuntime( 7421):    at android.widget.SimpleCursorAdapter.<init>  (SimpleCursorAdapter.java:87)

E/AndroidRuntime( 7421):    at com.orderdelivery.OrderList$SimpleOrderAdapter.<init>   (OrderList.java:171)

E/AndroidRuntime( 7421):    at com.orderdelivery.OrderList.onCreate(OrderList.java:74)

E/AndroidRuntime( 7421):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

E/AndroidRuntime( 7421):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

E/AndroidRuntime( 7421):    ... 11 more

W/ActivityManager(   58):   Force finishing activity com.orderdelivery/.OrderList

W/ActivityManager(   58): Activity pause timeout for HistoryRecord{43f91798     com.orderdelivery/.OrderList}

I/ARMAssembler(   58): generated scanline__00000077:03515104_00000000_00000000 [ 33    ipp] (47 ins) at [0x329870:0x32992c] in 2032590 ns

D/AndroidRuntime( 7435): 

Your SimpleOrderAdapter subclasses SimpleCursorAdapter . 您的SimpleOrderAdapter子类化SimpleCursorAdapter You create it with a cursor (the result from your query) and null values for from and to . 您可以使用游标(查询的结果)以及fromto null值来创建它。 According to the javadoc, this is only allowed when the cursor is not available yet . 根据javadoc,这仅在游标尚不可用时才允许。

I see, that the application crashes during creation of a new SimpleOrderAdapter instance and therefor after the query. 我看到,在创建新的SimpleOrderAdapter实例期间,应用程序在查询崩溃。 Looks to me, that you have to create this adapter with real values (column names and the indexes/ids of the text views). 在我看来,您必须使用实际值(列名和文本视图的索引/ ID)创建此适配器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM