Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid and sqlite difficulties
    primarykey
    data
    text
    <p>I'm new to android and Sq-lite and I cannot seem to get this database class to work. On the home screen you select a country, it then moves to the data screen and displays that data for the corresponding country, but I cannot seen to load the database it produces the following errors in logCat, please let me know if you need more details, any help would be great:</p> <pre><code>06-12 19:44:59.893: E/Trace(1215): error opening trace file: No such file or directory (2) 06-12 19:45:00.923: I/Choreographer(1215): Skipped 58 frames! The application may be doing too much work on its main thread. 06-12 19:45:01.003: D/gralloc_goldfish(1215): Emulator without GPU emulation det`enter code here`ected. 06-12 19:45:03.803: D/AndroidRuntime(1215): Shutting down VM 06-12 19:45:03.803: W/dalvikvm(1215): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 06-12 19:45:03.843: E/AndroidRuntime(1215): FATAL EXCEPTION: main 06-12 19:45:03.843: E/AndroidRuntime(1215): java.lang.IllegalStateException: getDatabase called recursively 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:204) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164) 06-12 19:45:03.843: E/AndroidRuntime(1215): at com.Jamie.dosanddonts.DosAndDontsDbAdapter.populateTable(DosAndDontsDbAdapter.java:43) 06-12 19:45:03.843: E/AndroidRuntime(1215): at com.Jamie.dosanddonts.DosAndDontsDbAdapter.onCreate(DosAndDontsDbAdapter.java:37) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188) 06-12 19:45:03.843: E/AndroidRuntime(1215): at com.Jamie.dosanddonts.DosAndDontsDbAdapter.findCountry(DosAndDontsDbAdapter.java:341) 06-12 19:45:03.843: E/AndroidRuntime(1215): at com.Jamie.dosanddonts.HomeScreen$1.onClick(HomeScreen.java:38) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.view.View.performClick(View.java:4204) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.view.View$PerformClick.run(View.java:17355) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.os.Handler.handleCallback(Handler.java:725) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.os.Handler.dispatchMessage(Handler.java:92) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.os.Looper.loop(Looper.java:137) 06-12 19:45:03.843: E/AndroidRuntime(1215): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-12 19:45:03.843: E/AndroidRuntime(1215): at java.lang.reflect.Method.invokeNative(Native Method) 06-12 19:45:03.843: E/AndroidRuntime(1215): at java.lang.reflect.Method.invoke(Method.java:511) 06-12 19:45:03.843: E/AndroidRuntime(1215): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-12 19:45:03.843: E/AndroidRuntime(1215): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-12 19:45:03.843: E/AndroidRuntime(1215): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Here is my class:</p> <pre><code>package com.Jamie.dosanddonts; import java.util.ArrayList; import java.util.List; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.widget.TextView; public class DosAndDontsDbAdapter extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; private static final String DATABASE_TABLE = "dosAndDonts"; private static final String COUNTRY = "Country name"; private static final String INDICATOR = "Indicator"; private static final String DESCRIPTION = "Description"; private TextView temp; private Country currentCountry; public DosAndDontsDbAdapter(Context context) { super(context, DATABASE_TABLE, null,DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub String CREATE_TABLE = "CREATE TABLE " + DATABASE_TABLE + "(" + COUNTRY + " TEXT," + INDICATOR + " TEXT," + DESCRIPTION + " TEXT" + ")"; db.execSQL(CREATE_TABLE); populateTable(); } public void populateTable() { SQLiteDatabase db = this.getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Shake hands when you greet someone."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Do say 'bonjour' or 'bonsoir'."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Flowers should be given in odd numbers but not 13."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Always smile"); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Always arrive on time for dinner."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "When eating Do not rest your elbows on the table."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Don't refer to someone by their first name unless you are a close friend."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Never offer cheap wine."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not begin eating until the hostess says 'bon appetit' "); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "France"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not cut salad with a knife and fork. Fold the lettuce on to your fork. "); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Shake hands when greeting and leaving someone."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "When you have finished eating lay your knide and fork parallel across your plate."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "When in a pub pay for a round of drinks for everyone in your group."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "When eating The fork is held tines down so food is scooped on to the back of the fork."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "When eating, Table manners are Continental."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Never get in their personal space."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "It's inapropriate to ask personal questions."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "They'll become unconfortalbe if engage in prolonged eye contact."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "When eating don't rest your elbows on the table."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "United_Kingdom"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "DON'T make the V for victory sign with your palm facing yourself."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "When greeting The usual handshake with direct eye contact."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Have calling card made."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "If you bring wine, make sure it is a good vintage."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "If you are invited to a meal, bring gift-wrapped such as wine or chocolates. "); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Table manners are Continental."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Never give your business card in lieu of a calling card in a social situation."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not give chrysanthemums as they are used at funerals."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not keep your hands in your lap during the meal."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not give red flowers as they indicate secrecy. "); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Italy"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not give yellow flowers as they indicate jealousy."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "A quick, firm handshake is the traditional greeting."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Titles are very important and denote respect."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "When entering a room, shake hands with everyone individually."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Yellow roses or tea roses are always well received. "); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "If you bring wine, it should be imported."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not give lilies or chrysanthemums as they are used at funerals. "); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Never arrive early, aslways on time."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not begin eating until the hostess starts."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not rest your elbows on the table."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Germany"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not cut lettuce in a salad. Fold it using your knife and fork."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Many men use a two-handed shake."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Always bring a gift to someones house."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Always keep your hands visible when eating."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "Use utensils to eat most food."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Do"); cv.put(DESCRIPTION, "If you have not finished eating, cross your knife and fork on your plate."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not begin eating until the hostess starts.  "); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Do not get up until the guest of honour does. "); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Never toast first always allow the host to."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "When at dinner don't sit unless invited to do so."); db.insert(DATABASE_TABLE, null, cv); cv.clear(); cv.put(COUNTRY, "Spain"); cv.put(INDICATOR, "Dont"); cv.put(DESCRIPTION, "Don't go bare cheasted anywhere other than the beach or poolside."); db.insert(DATABASE_TABLE, null, cv); db.close(); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } public void findCountry(String country) { int index = 0; SQLiteDatabase mDb = this.getReadableDatabase(); List &lt;DosAndDonts&gt; dosNDonts = new ArrayList &lt;DosAndDonts&gt;(); Cursor cursor = mDb.query(DATABASE_TABLE, new String[] {INDICATOR, DESCRIPTION }, COUNTRY + "=?", new String[] { String.valueOf(country) }, null, null, null, null); Country returnedCountry = new Country(); returnedCountry.setName(country); while(cursor.moveToNext()) { dosNDonts.add(new DosAndDonts(cursor.getString(index), cursor.getString(index + 1))); index = index + 2; } returnedCountry.setCountryDosAndDonts(dosNDonts); currentCountry = returnedCountry; this.displayResult(); } public void displayResult() { TextView country = (TextView) temp.findViewById(R.id.Country_name); TextView do1 = (TextView) temp.findViewById(R.id.Do1); TextView do2 = (TextView) temp.findViewById(R.id.Do2); TextView do3 = (TextView) temp.findViewById(R.id.Do3); TextView do4 = (TextView) temp.findViewById(R.id.Do4); TextView do5 = (TextView) temp.findViewById(R.id.Do5); TextView dont1 = (TextView) temp.findViewById(R.id.Dont1); TextView dont2 = (TextView) temp.findViewById(R.id.Dont2); TextView dont3 = (TextView) temp.findViewById(R.id.Dont3); TextView dont4 = (TextView) temp.findViewById(R.id.Dont4); TextView dont5 = (TextView) temp.findViewById(R.id.Dont5); TextView dos[] = { do1, do2, do3, do4, do5 }; TextView donts[] = { dont1, dont2, dont3, dont4, dont5 }; int doCounter = 0; int dontCounter = 0; int index = 0; List &lt;DosAndDonts&gt; dosNDonts = currentCountry.getCountryDosAndDonts(); country.setText(currentCountry.getName()); while (index &lt; dosNDonts.size()) { if (dosNDonts.get(index).getIndicator().equals("Do")) { dos[doCounter].setText(dosNDonts.get(index).getDescription()); doCounter++; } else { donts[dontCounter].setText(dosNDonts.get(index).getDescription()); dontCounter++; } index++; } } } </code></pre> <p>Hi thanks for your response, I have made the changes on the onCreate() and populate() methods and now get this set of error messages in my logCat starting from (1) and the set of messages repeats itself about 50 times, again any help would be great.</p> <pre><code>06-12 19:53:00.803: I/Choreographer(1549): Skipped 56 frames! The application may be doing too much work on its main thread. 06-12 19:53:00.873: D/gralloc_goldfish(1549): Emulator without GPU emulation detected. 06-12 19:53:04.593: E/SQLiteLog(1549): (1) near "name": syntax error 06-12 19:53:04.653: E/SQLiteDatabase(1549): Error inserting Country name=France Description=Shake hands when you greet someone. Indicator=Do 06-12 19:53:04.653: E/SQLiteDatabase(1549): android.database.sqlite.SQLiteException: near "name": syntax error (code 1): , while compiling: INSERT INTO dosAndDonts(Country name,Description,Indicator) VALUES (?,?,?) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteStatement.&lt;init&gt;(SQLiteStatement.java:31) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at com.Jamie.dosanddonts.DosAndDontsDbAdapter.populateTable(DosAndDontsDbAdapter.java:49) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at com.Jamie.dosanddonts.DosAndDontsDbAdapter.onCreate(DosAndDontsDbAdapter.java:37) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at com.Jamie.dosanddonts.DosAndDontsDbAdapter.findCountry(DosAndDontsDbAdapter.java:341) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at com.Jamie.dosanddonts.HomeScreen$1.onClick(HomeScreen.java:38) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.view.View.performClick(View.java:4204) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.view.View$PerformClick.run(View.java:17355) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.os.Handler.handleCallback(Handler.java:725) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.os.Handler.dispatchMessage(Handler.java:92) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.os.Looper.loop(Looper.java:137) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at java.lang.reflect.Method.invokeNative(Native Method) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at java.lang.reflect.Method.invoke(Method.java:511) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-12 19:53:04.653: E/SQLiteDatabase(1549): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload