Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems in creation database table Android
    text
    copied!<p>I've written my android app, it uses a database, here the onCreate method:</p> <pre><code>@Override public void onCreate(SQLiteDatabase database) { database.execSQL(CREATE_PARK_DETAILS); insertParks(database); database.execSQL(CREATE_DIARY); } </code></pre> <p>On my Samsung Galaxy S2 it works, like on other 100 people phones which downloaded the app from the store. But, one user has problems on his Sony-Ericsson Xperia Arc (LT15i) with Android 2.3.4. So I gave to test the app to other people using different phone, one of these has the same problem on Android 4.1...an SQLException.<br>After that I figured out that on this devices the second table is not being created, but only the the first one. <br>Why?</p> <p>CREATE_PARK_DETAILS:</p> <pre><code>CREATE TABLE cableparks (id int, name varchar(100), city varchar(100), state varchar(50), logo varchar(50), xCoord int, yCoord int, url varchar(100) DEFAULT '', street varchar(100) DEFAULT '', cap varchar(10) DEFAULT '', PRIMARY KEY (id)); </code></pre> <p>CREATE_DIARY:</p> <pre><code>CREATE TABLE diary (id int, comment text, addDate long, PRIMARY KEY (id), FOREIGN KEY (id) REFERENCES cableparks (id)); </code></pre> <p>LogCat:</p> <pre><code>08-21 21:29:01.402: E/SQLiteLog(12388): (1) no such table: diary 08-21 21:29:01.402: D/dalvikvm(12388): GC_CONCURRENT freed 176K, 7% free 10130K/10823K, paused 4ms+7ms, total 61ms 08-21 21:29:01.414: W/CursorWrapperInner(12388): Cursor finalized without prior close() 08-21 21:29:01.453: E/TAG(12388): getFavorite 08-21 21:29:01.453: E/TAG(12388): android.database.sqlite.SQLiteException: no such table: diary (code 1): , while compiling: SELECT * FROM diary WHERE id=31; 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58) 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37) 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314) 08-21 21:29:01.453: E/TAG(12388): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253) 08-21 21:29:01.453: E/TAG(12388): at com.emaborsa.cablePark.db.DatabaseManager.getFavorite(DatabaseManager.java:133) 08-21 21:29:01.453: E/TAG(12388): at com.emaborsa.cablePark.db.DatabaseManager.getPark(DatabaseManager.java:122) 08-21 21:29:01.453: E/TAG(12388): at com.emaborsa.cablePark.activities.SinglePark.onCreate(SinglePark.java:120) 08-21 21:29:01.453: E/TAG(12388): at android.app.Activity.performCreate(Activity.java:5008) 08-21 21:29:01.453: E/TAG(12388): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 08-21 21:29:01.453: E/TAG(12388): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 08-21 21:29:01.453: E/TAG(12388): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 08-21 21:29:01.453: E/TAG(12388): at android.app.ActivityThread.access$600(ActivityThread.java:130) 08-21 21:29:01.453: E/TAG(12388): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 08-21 21:29:01.453: E/TAG(12388): at android.os.Handler.dispatchMessage(Handler.java:99) 08-21 21:29:01.453: E/TAG(12388): at android.os.Looper.loop(Looper.java:137) 08-21 21:29:01.453: E/TAG(12388): at android.app.ActivityThread.main(ActivityThread.java:4745) 08-21 21:29:01.453: E/TAG(12388): at java.lang.reflect.Method.invokeNative(Native Method) 08-21 21:29:01.453: E/TAG(12388): at java.lang.reflect.Method.invoke(Method.java:511) 08-21 21:29:01.453: E/TAG(12388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 08-21 21:29:01.453: E/TAG(12388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 08-21 21:29:01.453: E/TAG(12388): at dalvik.system.NativeStart.main(Native Method) 08-21 21:29:01.496: D/AndroidRuntime(12388): Shutting down VM 08-21 21:29:01.496: W/dalvikvm(12388): threadid=1: thread exiting with uncaught exception (group=0x41b35300) 08-21 21:29:01.504: E/AndroidRuntime(12388): FATAL EXCEPTION: main 08-21 21:29:01.504: E/AndroidRuntime(12388): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emaborsa.cablePark/com.emaborsa.cablePark.activities.SinglePark}: java.lang.NullPointerException 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.app.ActivityThread.access$600(ActivityThread.java:130) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.os.Handler.dispatchMessage(Handler.java:99) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.os.Looper.loop(Looper.java:137) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.app.ActivityThread.main(ActivityThread.java:4745) 08-21 21:29:01.504: E/AndroidRuntime(12388): at java.lang.reflect.Method.invokeNative(Native Method) 08-21 21:29:01.504: E/AndroidRuntime(12388): at java.lang.reflect.Method.invoke(Method.java:511) 08-21 21:29:01.504: E/AndroidRuntime(12388): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 08-21 21:29:01.504: E/AndroidRuntime(12388): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 08-21 21:29:01.504: E/AndroidRuntime(12388): at dalvik.system.NativeStart.main(Native Method) 08-21 21:29:01.504: E/AndroidRuntime(12388): Caused by: java.lang.NullPointerException 08-21 21:29:01.504: E/AndroidRuntime(12388): at com.google.android.maps.ItemizedOverlay.populate(ItemizedOverlay.java:312) 08-21 21:29:01.504: E/AndroidRuntime(12388): at com.emaborsa.cablePark.map.route.LocationOverlay.addOverlay(LocationOverlay.java:21) 08-21 21:29:01.504: E/AndroidRuntime(12388): at com.emaborsa.cablePark.activities.SinglePark.setViewValues(SinglePark.java:180) 08-21 21:29:01.504: E/AndroidRuntime(12388): at com.emaborsa.cablePark.activities.SinglePark.onCreate(SinglePark.java:129) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.app.Activity.performCreate(Activity.java:5008) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 08-21 21:29:01.504: E/AndroidRuntime(12388): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 08-21 21:29:01.504: E/AndroidRuntime(12388): ... 11 more </code></pre> <p>GetFavorite method:</p> <pre><code>public FavoritePark getFavorite(int parkId) { FavoritePark favorite = null; String query = "SELECT * FROM " + TABLE_DIARY + " WHERE " + ID + "=" + parkId + ";"; try { Cursor cursor = database.rawQuery(query, null); try { if (cursor.moveToFirst()) { int commentIndex = cursor.getColumnIndex(COMMENT); String comment = cursor.getString(commentIndex); int addedIndex = cursor.getColumnIndex(ADD_TIME); Date added = new Date(cursor.getLong(addedIndex)); favorite = new FavoritePark(comment, added); } } finally { try { cursor.close(); } catch (Throwable ignore) {} } } catch (Exception e) { Log.e("TAG", "getFavorite", e); } return favorite; } </code></pre>
 

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