Error displaying database within a ListView
I am displaying my database in a ListView
. I used a Button
named find geopoint
for displaying the database. when I click on it, the application crashes. Here is the stack trace:
08-25 17:03:11.308: ERROR/AndroidRuntime(8373): Uncaught handler: thread main exiting due to uncaught exception
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cortes/com.cortes.Display}: java.lang.IllegalStateException: get field slot from row 1 col -1 failed
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.os.Handler.dispatchMessage(Handler.java:99)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.os.Looper.loop(Looper.java:123)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.app.ActivityThread.main(ActivityThread.java:4363)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at java.lang.reflect.Method.invokeNative(Native Method)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at java.lang.reflect.Method.invoke(Method.java:521)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at dalvik.system.NativeStart.main(Native Method)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): Caused by: java.lang.IllegalStateException: get field slot from row 1 col -1 failed
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.database.CursorWindow.getString_native(Native Method)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.database.CursorWindow.getString(CursorWindow.java:363)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at com.cortes.Display.onCreate(Display.java:116)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
08-25 17:03:11.338: ERROR/AndroidRuntime(8373): ... 11 more
Here is my code:
c = db.query(Geo_Create_Table, new String[ {"_id","latitude","longitude","address"}, null,null, null, null, null);
x1 = c.getColumnIndex("_id");
y1 = c.getColumnIndex("latitude");
z1 = c.getColumnIndex("longiitude");
w1 = c.getColumnIndex("address");
while(c.moveToNext()) {
a = c.getInt(x1);
b1 = c.getString(y1);
c1 = c.getString(z1);
e = c.getString(w1);
results.add(a+"" + " " + b1 + " " + c1 + " " + e);
}
ArrayAdapter<String> a11=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, results);
lv.setAdapter(a11);
Here is my AndroidManifest.xml
file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cortes"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
<uses-library
android:required="true"
android:name="com.google.android.maps"/>
<activity
android:name=".C开发者_StackOverflowortes"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Display"
android:label="@string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Any suggestions on how to solve this problem?
精彩评论