在我的应用程序中,我有一个 SQLite 数据库,我想知道如何将一些数据(例如 id、title 等)传输到另一个活动。
到目前为止,这是我的代码:
ListView lv = getListView();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
public void onItemClick(AdapterView<?> av, View v, int pos, long id)
{
onListItemClick(v,pos,id);
}
protected void onListItemClick(View v, int pos, long id)
{
Intent i = new Intent(context, Table.class);
i.putExtra("Value1", c.getString(c.getColumnIndex("title")));
startActivity(i);
}
});
但我收到错误。
01-29 12:25:46.511: E/AndroidRuntime(26478): FATAL EXCEPTION: main
01-29 12:25:46.511: E/AndroidRuntime(26478): android.database.CursorIndexOutOfBoundsException: Index 50 requested, with a size of 50
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
01-29 12:25:46.511: E/AndroidRuntime(26478): at com.example.studentdatabase.MainActivity$2.onListItemClick(MainActivity.java:90)
01-29 12:25:46.511: E/AndroidRuntime(26478): at com.example.studentdatabase.MainActivity$2.onItemClick(MainActivity.java:87)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.widget.AdapterView.performItemClick(AdapterView.java:284)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.widget.ListView.performItemClick(ListView.java:3513)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.os.Handler.handleCallback(Handler.java:587)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.os.Handler.dispatchMessage(Handler.java:92)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.os.Looper.loop(Looper.java:123)
01-29 12:25:46.511: E/AndroidRuntime(26478): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-29 12:25:46.511: E/AndroidRuntime(26478): at java.lang.reflect.Method.invokeNative(Native Method)
01-29 12:25:46.511: E/AndroidRuntime(26478): at java.lang.reflect.Method.invoke(Method.java:507)
01-29 12:25:46.511: E/AndroidRuntime(26478): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-29 12:25:46.511: E/AndroidRuntime(26478): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-29 12:25:46.511: E/AndroidRuntime(26478): at dalvik.system.NativeStart.main(Native Method)
请帮忙,谢谢。