Uncaught handler

E

eintagsfliege

Gast
Hallo!
Ich versuche immoment eine Liste mit Einträgen aus einer Datenbank darzustellen, jedoch bekomme ich folgende Fehler:
Uncaught handler: thread main exiting due to uncaught exception
Mein Code ist:
Code:
package com.application.edaytips;

import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;


public class categories extends ListActivity {

    final static String MY_DB_NAME = "alltagstipps";
     final static String MY_DB_TABLE_1 = "categories";
     final static String MY_DB_TABLE_2 = "content";
    @Override     
     public void onCreate(Bundle savedInstance) {
         setContentView(R.layout.categories);

                   SQLiteDatabase myDB = null;

                  myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
                  Cursor c = myDB.rawQuery("SELECT _id, title FROM " + MY_DB_TABLE_1, null);
                  startManagingCursor(c);    
                  

           // the desired columns to be bound
           String[] columns = new String[] { "_id", "title" };
           // the XML defined views which the data will be bound to
           int[] to = new int[] { R.id.lv_categories_item_text, R.id.lv_categories_item_text2 };

           // create the adapter using the cursor pointing to the desired data as well as the layout information
           SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.categories_list, c, columns, to);

           // set this adapter as your ListActivity's adapter
           this.setListAdapter(mAdapter);
     }
}

Kann mir jemand sagen, was ich falsch mache? Bin leider noch Anfänger :-(
 
Dahinter werden ja noch mehr Fehlermeldungen kommen, denn mit der obigen kann man erstmal nichts anfangen.
 
Ja da kommen noch weitere Fehlermeldungen, jedoch schaue ich schon überall nach Tutorials und finde einfach keine Lösung :(
 
Ja wenn du uns die zeigen würdest könnten wir die evtl. helfen.
Dort wird nämlich (meistens) die Zeile angegeben, in der der Fehler auftrat.
 
Die Fehlermeldungen sind folgende:
06-06 20:39:26.810: ERROR/AndroidRuntime(424): Uncaught handler: thread main exiting due to uncaught exception
06-06 20:39:26.850: ERROR/AndroidRuntime(424): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.application.edaytips/com.application.edaytips.categories}: android.database.sqlite.SQLiteException: no such table: categories: , while compiling: SELECT _id, title FROM categories
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.os.Handler.dispatchMessage(Handler.java:99)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.os.Looper.loop(Looper.java:123)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.app.ActivityThread.main(ActivityThread.java:4203)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at java.lang.reflect.Method.invokeNative(Native Method)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at java.lang.reflect.Method.invoke(Method.java:521)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at dalvik.system.NativeStart.main(Native Method)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): Caused by: android.database.sqlite.SQLiteException: no such table: categories: , while compiling: SELECT _id, title FROM categories
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:49)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1118)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1092)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at com.application.edaytips.categories.onCreate(categories.java:22)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
06-06 20:39:26.850: ERROR/AndroidRuntime(424): ... 11 more
Das xml für jede Zeile:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:paddingTop="2dip" android:paddingBottom="2dip" android:paddingLeft="6dip" android:paddingRight="6dip">
     <TextView android:layout_width="fill_parent" android:layout_height="46dip" android:textAppearance="?android:attr/textAppearanceMedium" android:gravity="center_vertical" android:id="@+id/lv_categories_item_text" android:layout_marginLeft="2dip"/>
     <TextView android:layout_width="fill_parent" android:layout_height="46dip" android:textAppearance="?android:attr/textAppearanceMedium" android:gravity="center_vertical" android:id="@+id/lv_categories_item_text2" android:layout_marginLeft="2dip"/>
</LinearLayout>
Und das xml für die Liste:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical" android:background="#1A1A1A">
  
  <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/categories" android:layout_marginTop="20dip"/>
  <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="none" android:id="@android:id/android:list" android:clickable="true"></ListView>
</LinearLayout>
Danke für die schnelle Antwort :)
 
Zuletzt bearbeitet von einem Moderator:
Ganz einfach, du darfst das super nicht vergessen: Steht so auch in der Fehlermeldung ;)

Code:
@Override     
public void onCreate(Bundle savedInstance) {
[B]super.onCreate(savedInstance[/B][B]);[/B]
setContentView(R.layout.categories);
 
Dankeschön :) Ja ich war irrtiert, da im Tutorial kein super hinzugefügt wurde:confused: Habe jetzt noch einige Änderungen gemacht (Einträge und Datenbnak erstellt) und jetzt funktioniert es! Danke danke:)

Ich habe noch eine Frage, die noch offen ist bezüglich des Codes:
Wie kann ich anstelle des Textviews z.B. lv_categories_item_text2 die Quelle eines ImageViews verändern. Ich habe z.B. die Bilder 1.png, 2.png, ... für verschiedene Kategorien und möchte diese je nach item vor den Text setzen.
Gebe ich dann anstatt von lv_categories_item_text2 im SimpleCursorAdapter einfach die Bild-ID an oder mache ich das so: SimpleCursorAdapter([...], R.id.lv_categories_item_image.setResource(@drawable/???.png),[...]) ?
 
Zuletzt bearbeitet von einem Moderator:

Ähnliche Themen

H
  • heikoj10.1
Antworten
4
Aufrufe
715
heikoj10.1
H
H
Antworten
7
Aufrufe
1.162
markus.tullius
markus.tullius
Z
Antworten
2
Aufrufe
1.250
DagobertDokate
DagobertDokate
Zurück
Oben Unten