English 中文(简体)
Fail to populatione ListView through briefcuror Adaptationer
原标题:Failing to populate ListView via Simplecursor Adapter

I want to populate my listview with the data from my database,but when i try to do that it just gives me one exception i.e.

 "04-27 13:15:51.139: E/AndroidRuntime(2575): Caused by: java.lang.IllegalArgumentException: column  _id  does not exist"

不管怎样适应我所使用,但我还是得到同样的例外。

这是我的<代码>SQLiteOpenHelper:

public class MySQLiteHelper extends SQLiteOpenHelper {

    //      Table Names
    public static final String TABLE_USER_MASTER = "USER_MASTER";
    public static final String TABLE_ORDER_MASTER = "ORDER_MASTER";
    public static final String TABLE_ORDER_DETAILS = "ORDER_DETAILS";

    //      Database Details
    public static String DB_NAME = "ezeefood.db";
    public static String DB_PATH = "/data/data/com.project.menuApp";
    public static final int DATABASE_VERSION = 4;

    //      User Detail Columns
    public static final String KEY_ID = "_id";
    public static final String KEY_NAME = "Name";
    public static final String KEY_ADDRESS = "Address";
    public static final String KEY_PHONE = "PhoneNo";
    public static final String KEY_USERNAME = "userid";
    public static final String KEY_PASSWORD = "password";

    //      Order Master Columns
    public static final String ORDER_ID = "order_id";
    public static final String ORDER_DATE = "date";
    public static final String ORDER_TIME = "time";

    //      Order Detail Columns
    public static final String ORDER_DETAIL_ID = "order_detail_id";
    public static final String ORDER_ITEM_NAME = "item_name";
    public static final String ORDER_ITEM_RATE = "item_rate";
    public static final String ORDER_ITEM_QTY = "item_qty";
    public static final String ORDER_ID_FINAL = "order_Id";

     private SQLiteDatabase sqLiteDatabase;

    private static final String SCRIPT_CREATE_TABLE_USER_MASTER = "CREATE  TABLE "
            + TABLE_USER_MASTER + "(" + KEY_ID
            + "  INTEGER PRIMARY KEY  AUTOINCREMENT," + KEY_USERNAME + " VARCHAR UNIQUE, "
            + KEY_PASSWORD + " VARCHAR," + KEY_NAME + " VARCHAR,"
            + KEY_ADDRESS + " VARCHAR," + KEY_PHONE + " VARCHAR);";

    private static final String SCRIPT_CREATE_TABLE_ORDER_MASTER = "CREATE  TABLE "
            + TABLE_ORDER_MASTER + "(" + ORDER_ID
            + "  INTEGER PRIMARY KEY  AUTOINCREMENT," + KEY_USERNAME + " VARCHAR, "
            + ORDER_DATE + " VARCHAR," + ORDER_TIME +" VARCHAR);";

    private static final String SCRIPT_CREATE_TABLE_ORDER_DETAILS = "CREATE  TABLE "
            + TABLE_ORDER_DETAILS + "(" + ORDER_DETAIL_ID
            + "  INTEGER PRIMARY KEY  AUTOINCREMENT," + ORDER_ID_FINAL + " INTEGER, "
            + ORDER_ITEM_NAME + " VARCHAR," + ORDER_ITEM_RATE + " FLOAT,"
            + ORDER_ITEM_QTY + " INTEGER DEFAULT 1);";

    public MySQLiteHelper(Context context) {
        super(context, DB_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase database) {
        database.execSQL(SCRIPT_CREATE_TABLE_USER_MASTER);
        database.execSQL(SCRIPT_CREATE_TABLE_ORDER_MASTER);
        database.execSQL(SCRIPT_CREATE_TABLE_ORDER_DETAILS);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        Log.w(MySQLiteHelper.class.getName(),
                "Upgrading database from version " + oldVersion + " to "
                        + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER_MASTER);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_ORDER_MASTER);
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_ORDER_DETAILS);
        onCreate(db);
    }
}

而这正是我试图通过简单的治疗师调用我的清单。

public class FinalOrder extends ListActivity {

    Cursor cursor;
    long orderId;
    private SQLiteDatabase mDatabase;
    private MySQLiteHelper mDbhelper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.orderdetails);
        Bundle c = getIntent().getExtras();
        orderId = c.getLong("orderID");
        mDbhelper = new MySQLiteHelper(this);
        mDatabase = mDbhelper.getReadableDatabase();    
        cursor = mDatabase.query(MySQLiteHelper.TABLE_ORDER_DETAILS, new String [] {MySQLiteHelper.ORDER_ITEM_NAME,
                MySQLiteHelper.ORDER_ITEM_QTY,MySQLiteHelper.ORDER_ITEM_RATE}, "order_Id = ?",
                new String[]{String.valueOf(orderId)}, null, null, null);
        startManagingCursor(cursor);

        String[] from = new String[] {MySQLiteHelper.ORDER_ITEM_NAME,MySQLiteHelper.ORDER_ITEM_QTY,MySQLiteHelper.ORDER_ITEM_RATE};
        int[] to = new int[] {R.id.tv_listItemName,R.id.tv_listItemQTY,R.id.tv_listItemPrice};

        ListAdapter adapter = new SimpleCursorAdapter(this,R.layout.orderlist_row,cursor,from,to);

        setListAdapter(adapter);
    }
}

我不禁要问,为什么它只提供一种例外,即没有在座标上注明“_id”的栏目。 请确实提供帮助。 谢谢!

问题回答

页: 1 TABLE_ORDER_DETAILS table which has a ORDER_DETAIL_ID 页: 1 如果您从<条码>改为: 简单的CursorAdapter期望在曲线上打上一个名为的栏目。

您还必须把id栏列入询问。 快速固定,不重新命名表中的栏目,将重新命名为:

    cursor = mDatabase.query(MySQLiteHelper.TABLE_ORDER_DETAILS,
            new String [] { MySQLiteHelper.ORDER_DETAIL_ID + " AS _id",
            MySQLiteHelper.ORDER_ITEM_NAME,
            MySQLiteHelper.ORDER_ITEM_QTY,
            MySQLiteHelper.ORDER_ITEM_RATE }, "order_Id = ?",
            new String[]{String.valueOf(orderId)}, null, null, null);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...