Just to add, it gives me the same error even when i completely change the query and remove the apparently non existent column. I'm really confused!
On Sep 3, 2:43 am, kingh32 <[email protected]> wrote: > Thank you for both of your replies. I have tried implementing both of > your suggestions but neither has worked. > I've found another way to do it though and I've had some success > although displaying it as a listview seems to be really difficult. > > This is what I've written... > > package com.targetshooterapp; > > public class DBAdapter extends ListActivity > { > // These variables to be retrieved from the Intent Bundle > > /** Unique ID assigned to competitors once entering an event */ > int entryID; > /** Unique identifier for shots */ > int shotID; > /** Name of the event */ > String eventName="Tester"; > /** Event Date */ > String date="Date"; > /** Type of event */ > String eventType="Service Pistol"; > /** Number of rounds */ > int numRounds=1; > /** Number of shots per round */ > int shotsPerRound=4; > /** Name of user */ > String shooter="me"; > /** Distance from the target */ > String distance="100 yards"; > /** Total score at the end of the event*/ > int totalScore=10; > /** x coordinate of user input on screen */ > float xCoord = (float) 345.675; > /** y coordinate of user input on screen */ > float yCoord = (float) 345.675; > /** Event table - String name */ > private final String EVENT_TABLE = "tbl_event"; > /** Shot table - String name */ > private final String SHOT_TABLE = "tbl_event"; > > SQLiteDatabase db; > public void onCreate(Bundle savedInstanceState) > { > super.onCreate(savedInstanceState); > // Create Array List to store result > ArrayList<String> result = new ArrayList<String>(); > try > { > db = openOrCreateDatabase("shootnext.db", > SQLiteDatabase.CREATE_IF_NECESSARY, null); > // Set DB version, Locale and locking properties of > the database > db.setVersion(1); > db.setLocale(Locale.getDefault()); > db.setLockingEnabled(true); > > /** SQL query to create the event table */ > final String CREATE_TABLE_EVENT = "CREATE TABLE IF > NOT EXISTS > tbl_event(" > + "entryID INTEGER PRIMARY KEY , " > + "eventName TEXT," > + "date TEXT," > + "eventType TEXT," > + "numRounds INTEGER," > + "shotsPerRound, INTEGER" > + "shooter TEXT," > + "distance TEXT," > + "totalScore INTEGER);"; > > /** SQL query to create the shot table */ > final String CREATE_TABLE_SHOT = "CREATE TABLE IF NOT > EXISTS tbl_shot(" > + "shotID INTEGER PRIMARY KEY , " > + "entryID INTEGER," > + "xCoord FLOAT," > + "yCoord FLOAT," > + "points INTEGER," > + "shooter TEXT);"; > > // Create tables in the database > db.execSQL(CREATE_TABLE_EVENT); > db.execSQL(CREATE_TABLE_SHOT); > > // SQL query to enter event details into database > String INSERT_INTO_EVENT = "INSERT INTO tbl_event > VALUES" > +"(5,'" > + eventName > +"','" > + date > +"','" > + eventType > +"','" > + numRounds > +"','" > + shotsPerRound > +"','" > + shooter > +"','" > + distance > +"','" > + totalScore +"');"; > > String INSERT_INTO_SHOT = "INSERT INTO tbl_shot > VALUES" > +"(17,'" > + 34 +"','" > + xCoord +"','" > + yCoord +"','" > + totalScore +"','" > + shooter +"');"; > > //db.execSQL(INSERT_INTO_EVENT); > //db.execSQL(INSERT_INTO_SHOT); > > Cursor cursor = db.rawQuery("SELECT > eventName,shooter" + > " FROM " + EVENT_TABLE > + " WHERE totalScore > 10 LIMIT 10", > null); > > if(cursor != null) > { > if(cursor.moveToFirst()) > { > do > { > String eName = > cursor.getString(cursor.getColumnIndex("eventName")); > String sName = > cursor.getString(cursor.getColumnIndex("shooter")); > int tScore = > cursor.getInt(cursor.getColumnIndex("totalScore")); > //result.add("" + eName + "" > + "Name: "+ sName + ", > Score: " + tScore); > result.add("" + eName + > ",Shooter: " + sName); > } > while(cursor.moveToNext()); > } > } > > this.setListAdapter(new ArrayAdapter<String>(this, > android.R.layout.simple_list_item_1, result)); > > } > catch(SQLiteException se) > { > Log.e(getClass().getSimpleName(), "Can't get in!"); > } > finally > { > if(db != null) > { > db.execSQL("DELETE * FROM " + EVENT_TABLE); > db.execSQL("DELETE * FROM " + SHOT_TABLE); > db.close(); > } > } > } > > } > > I have also posted the log output > > I/ActivityManager( 67): Starting activity: Intent > { cmp=com.targetshooterapp/. > History } > D/AndroidRuntime( 685): Shutting down VM > W/dalvikvm( 685): threadid=3: thread exiting with uncaught exception > (group=0x4 > 001aa28) > E/AndroidRuntime( 685): Uncaught handler: thread main exiting due to > uncaught e > xception > E/AndroidRuntime( 685): java.lang.RuntimeException: Unable to start > activity Co > mponentInfo{com.targetshooterapp/com.targetshooterapp.History}: > android.database > .sqlite.SQLiteException: no such column: shooter: , while compiling: > SELECT even > tName,shooter FROM tbl_event WHERE totalScore > 10 LIMIT 10 > E/AndroidRuntime( 685): at > android.app.ActivityThread.performLaunchActiv > ity(ActivityThread.java:2401) > E/AndroidRuntime( 685): at > android.app.ActivityThread.handleLaunchActivi > ty(ActivityThread.java:2417) > E/AndroidRuntime( 685): at android.app.ActivityThread.access > $2100(Activi > tyThread.java:116) > E/AndroidRuntime( 685): at android.app.ActivityThread > $H.handleMessage(Ac > tivityThread.java:1794) > E/AndroidRuntime( 685): at > android.os.Handler.dispatchMessage(Handler.ja > va:99) > E/AndroidRuntime( 685): at android.os.Looper.loop(Looper.java: > 123) > E/AndroidRuntime( 685): at > android.app.ActivityThread.main(ActivityThrea > d.java:4203) > E/AndroidRuntime( 685): at > java.lang.reflect.Method.invokeNative(Native > Method) > E/AndroidRuntime( 685): at > java.lang.reflect.Method.invoke(Method.java:5 > 21) > E/AndroidRuntime( 685): at com.android.internal.os.ZygoteInit > $MethodAndA > rgsCaller.run(ZygoteInit.java:791) > E/AndroidRuntime( 685): at > com.android.internal.os.ZygoteInit.main(Zygot > eInit.java:549) > E/AndroidRuntime( 685): at > dalvik.system.NativeStart.main(Native Method) > > E/AndroidRuntime( 685): Caused by: > android.database.sqlite.SQLiteException: no > such column: shooter: , while compiling: SELECT eventName,shooter FROM > tbl_event > WHERE totalScore > 10 LIMIT 10 > E/AndroidRuntime( 685): at > android.database.sqlite.SQLiteProgram.native_ > compile(Native Method) > E/AndroidRuntime( 685): at > android.database.sqlite.SQLiteProgram.compile > (SQLiteProgram.java:110) > E/AndroidRuntime( 685): at > android.database.sqlite.SQLiteProgram.<init>( > SQLiteProgram.java:59) > E/AndroidRuntime( 685): at > android.database.sqlite.SQLiteQuery.<init>(SQ > LiteQuery.java:49) > E/AndroidRuntime( 685): at > android.database.sqlite.SQLiteDirectCursorDri > ver.query(SQLiteDirectCursorDriver.java:49) > E/AndroidRuntime( 685): at > android.database.sqlite.SQLiteDatabase.rawQue > ryWithFactory(SQLiteDatabase.java:1118) > E/AndroidRuntime( 685): at > android.database.sqlite.SQLiteDatabase.rawQue > ry(SQLiteDatabase.java:1092) > E/AndroidRuntime( 685): at > com.targetshooterapp.History.onCreate(History > .java:121) > E/AndroidRuntime( 685): at > android.app.Instrumentation.callActivityOnCre > ate(Instrumentation.java:1123) > E/AndroidRuntime( 685): at > android.app.ActivityThread.performLaunchActiv > > It says there is no such column: shooter: in the databsae, but there > is. I've added stuff to it and its fine. > > Any ideas? > > On Sep 1, 6:45 pm, Kostya Vasilyev <[email protected]> wrote: > > > > > The "from" and "to" arrays need to have equal size, and contain values > > (column names and view ids) that are used for mapping data to UI elements. > > > Your code seems to try and map a number of data column items into one > > text view. > > > The fix is to add more elements to the item layout, and specify themin > > the "to" array, so each column in the "from" array is mapped to a view. > > > To display two (or more) tables, you use something called a "table > > join". It's a standard SQL construct, Google for it. > > > Finally, use logcat (in Eclipse or "adb logcat" on the host computer) to > > see more detailed information whenever your application crashes. > > > Including the Java stack trace from logcat output with your questions is > > also useful, as it helps others understand what goes on in your application. > > > -- Kostya > > > 01.09.2010 20:26, kingh32 пишет: > > > > // Set the list adapter > > > String[]from = {DBHelper.COL_ENTRYID, > > > DBHelper.COL_EVENTNAME, > > > DBHelper.COL_DATE, DBHelper.COL_EVENTTYPE, > > > DBHelper.COL_NUMROUNDS, > > > DBHelper.COL_PLAYSSPERROUND, > > > DBHelper.COL_PLAYERS, > > > DBHelper.COL_DISTANCE, > > > DBHelper.COL_TOTALSCORE}; > > > > int[]to = {R.id.the name of my textview}; > > > > // Put retrieved data into a list view > > > SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, > > > android.R.layout.simple_list_item_1, cursor, from, to); > > > -- > > Kostya Vasilyev -- WiFi Manager + pretty widget > > --http://kmansoft.wordpress.com -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

