数据库中的行无法显示

时间:2013-07-31 07:49:28

标签: android database sqlite row

很多次,我遇到了另一个问题,需要你的帮助。 我试图从活动中获取一个id数据并将其传递给另一个活动,它的工作原理。问题是没有错误,但我的数据来自某个id,我传递给第二个活动不会显示。 这是我的第一个活动:

lv.setOnItemClickListener(new OnItemClickListener()
{
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
 {
    // Intent newI = new Intent(this,PDetail.class); 
     Intent newI = new Intent (Create.this, PDetail.class);
     newI.putExtra("value", arg3);
     startActivity (newI);
    // db.getList(arg3);

 }});

这是我的第二项活动:

 public void get() {
    Bundle bundle = getIntent().getExtras();
    long count = bundle.getLong("value");
    TextView XView;
    //Toast.makeText(getApplicationContext(), count, Toast.LENGTH_SHORT).show();
    XView = (TextView) findViewById(R.id.textView1); 
    //XView.setText("Number: " + count);
    db.open();
    Cursor z = db.getList(count);
    z.moveToFirst(); 
    String a = z.getString(z.getColumnIndex("product"));
    XView.setText(a);
    db.close();

}

我没有错误,但只是强行关闭....任何线索???

这是db.getList

public Cursor getList(long rowId) throws SQLException
{
Cursor mCursor =
        db.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
        KEY_PRODUCT,KEY_BRAND, KEY_PLACE, KEY_DATE, KEY_PRICE}, KEY_ROWID + "=" + rowId, null,
        null, null, null, null);
        if (mCursor != null) {
        mCursor.moveToFirst();
        }
        return mCursor;
        }
        //---updates a contact---
        public boolean updateList(long rowId, String product, String brand, String place, String date, String price)
        {
        ContentValues args = new ContentValues();
        args.put(KEY_PRODUCT, product);
        args.put(KEY_BRAND, brand);
        args.put(KEY_PLACE, place);
        args.put(KEY_DATE, date);
        args.put(KEY_PRICE, price);
        return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) > 0;
        }

}

Logcat没有任何用处,我认为......

07-31 15:26:26.049: W/dalvikvm(20436): threadid=1: thread exiting with uncaught exception (group=0x40018578)
07-31 15:26:26.049: E/AndroidRuntime(20436): FATAL EXCEPTION: main
07-31 15:26:26.049: E/AndroidRuntime(20436): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test.first/com.test.first.PDetail}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.os.Looper.loop(Looper.java:130)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.app.ActivityThread.main(ActivityThread.java:3687)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at java.lang.reflect.Method.invokeNative(Native Method)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at java.lang.reflect.Method.invoke(Method.java:507)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at dalvik.system.NativeStart.main(Native Method)
07-31 15:26:26.049: E/AndroidRuntime(20436): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at com.test.first.PDetail.get(PDetail.java:32)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at com.test.first.PDetail.onCreate(PDetail.java:18)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-31 15:26:26.049: E/AndroidRuntime(20436):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
07-31 15:26:26.049: E/AndroidRuntime(20436):    ... 11 more

0 个答案:

没有答案