Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid sqlite application will not start and crashes immediately upon opening the app
    text
    copied!<p>I am currently working in eclipse with android adt and cannot get my application to open. I have tried cleaning the application and uninstalling it multiple times and I am not sure what else I can do to get my database to display the information. I am trying this on an emulator and on my motorola droid bionic android device. I am very new to programming in android so any type of help would be greatly appreciated and my code can be found below. The specifics of the eclipse software are:</p> <p>Eclipse SDK Version: 4.2.1 Build id: M20120914-1800</p> <p>Main activity where the database is created:</p> <pre><code>package com.example.database; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class MainActivity { public static final String KEY_ROWID = "_id"; public static final String KEY_BUSINESS = "business"; public static final String KEY_ADDRESS = "address"; public static final String KEY_PHONE = "phone"; public static final String KEY_HOURS = "hours"; public static final String KEY_WEB = "website"; private static final String TAG = "MainActivity"; private static final String DATABASE_NAME = "BloomBusiness"; private static final String DATABASE_TABLE = "Business"; private static final int DATABASE_VERSION = 1; private static final String DATABASE_CREATE = "create table Business (_id integer primary key autoincrement, " + "business text not null, address text not null, phone text not null, hours text not null" + "website text not null)"; private final Context context; private DatabaseHelper DBHelper; private SQLiteDatabase db; public MainActivity(Context ctx) { this.context = ctx; DBHelper = new DatabaseHelper(context); } private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(DATABASE_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); db.execSQL("DROP TABLE IF EXISTS Business"); onCreate(db); } } //---opens the database--- public MainActivity open() throws SQLException { db = DBHelper.getWritableDatabase(); return this; } //---closes the database--- public void close() { DBHelper.close(); } //---insert a title into the database--- public long insertTitle(String business, String address, String phone, String hours, String website) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_BUSINESS, business); initialValues.put(KEY_ADDRESS, address); initialValues.put(KEY_PHONE, phone); initialValues.put(KEY_HOURS, hours); initialValues.put(KEY_WEB, hours); return db.insert(DATABASE_TABLE, null, initialValues); } //---deletes a particular title--- public boolean deleteTitle(long rowId) { return db.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) &gt; 0; } //---retrieves all the titles--- public Cursor getAllTitles() { return db.query(DATABASE_TABLE, new String[] { KEY_ROWID, KEY_BUSINESS, KEY_ADDRESS, KEY_PHONE, KEY_HOURS, KEY_WEB}, null, null, null, null, null); } //---retrieves a particular title--- public Cursor getTitle(long rowId) throws SQLException { Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] { KEY_ROWID, KEY_BUSINESS, KEY_ADDRESS, KEY_PHONE, KEY_HOURS, KEY_WEB }, KEY_ROWID + "=" + rowId, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } //---updates a title--- public boolean updateTitle(long rowId, String business, String address, String phone, String hours, String website) { ContentValues args = new ContentValues(); args.put(KEY_BUSINESS, business); args.put(KEY_ADDRESS, address); args.put(KEY_PHONE, phone); args.put(KEY_HOURS,hours); args.put(KEY_WEB,website); return db.update(DATABASE_TABLE, args, KEY_ROWID + "=" + rowId, null) &gt; 0; } } </code></pre> <p>Database information being displayed:</p> <pre><code>package com.example.database; import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.widget.Toast; public class DBUse extends Activity { @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MainActivity db = new MainActivity(this); db.open(); Cursor c = db.getAllTitles(); if(c.moveToFirst()) { do{DisplayTitle(c); }while (c.moveToNext()); } db.open(); Cursor b = db.getTitle(1); if (b.moveToFirst()) DisplayTitle(c); else Toast.makeText(this,"No business found",Toast.LENGTH_LONG).show(); db.close(); db.close(); } public void DisplayTitle(Cursor c) { Toast.makeText(this, "Name: " + c.getString(1)+"\n"+ "Address:" + c.getString(2)+"\n"+ "Phone:" + c.getString(3)+"\n"+ "Hours:" + c.getString(4)+"\n"+ "Website"+ c.getShort(5), Toast.LENGTH_LONG).show(); } } </code></pre> <p>Database information being added:</p> <pre><code>package com.example.database; import android.app.Activity; import android.database.Cursor; import android.os.Bundle; import android.widget.Toast; public class DBActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MainActivity db= new MainActivity(this); db.open(); long id; id=db.insertTitle("BloomingFoods","419 E. Kirkwood Ave. Bloomington, IN", "812-336-5300", "M-S:8AM-9PM Sun:9am-8PM","http://www.bloomingfoods.coop"); id=db.insertTitle("BloomingFoods","316 W. 6th Street Bloomington, IN", "812-333-5300", "M-S:7AM-10PM Sun:9am-9PM","http://www.bloomingfoods.coop"); id=db.insertTitle("BloomingFoods","3220 E. 3rd Street Bloomington, IN", "812-336-5300", "M-Sun:8AM-10PM","http://www.bloomingfoods.coop"); id=db.insertTitle("The Uptown Cafe","102 E. Kirkwood Ave. Bloomington, IN", "812-339-0900", "M-S:8AM-9PM Sun:9am-8PM", "http://www.the-uptown.com/"); } } </code></pre> <p>The manifest:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.database" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /&gt; &lt;application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" &gt; &lt;activity android:name="com.example.database.DBUse" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>LogCat:</p> <pre><code>04-15 20:50:23.122: E/Trace(638): error opening trace file: No such file or directory (2) 04-15 20:50:24.062: E/SQLiteLog(638): (1) no such column: website 04-15 20:50:24.072: D/AndroidRuntime(638): Shutting down VM 04-15 20:50:24.072: W/dalvikvm(638): threadid=1: thread exiting with uncaught exception (group=0x40a13300) 04-15 20:50:24.084: E/AndroidRuntime(638): FATAL EXCEPTION: main 04-15 20:50:24.084: E/AndroidRuntime(638): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.database/com.example.database.DBUse}: android.database.sqlite.SQLiteException: no such column: website (code 1): , while compiling: SELECT _id, business, address, phone, hours, website FROM Business 04-15 20:50:24.084: E/AndroidRuntime(638): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.app.ActivityThread.access$600(ActivityThread.java:130) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.os.Handler.dispatchMessage(Handler.java:99) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.os.Looper.loop(Looper.java:137) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.app.ActivityThread.main(ActivityThread.java:4745) 04-15 20:50:24.084: E/AndroidRuntime(638): at java.lang.reflect.Method.invokeNative(Native Method) 04-15 20:50:24.084: E/AndroidRuntime(638): at java.lang.reflect.Method.invoke(Method.java:511) 04-15 20:50:24.084: E/AndroidRuntime(638): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 04-15 20:50:24.084: E/AndroidRuntime(638): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 04-15 20:50:24.084: E/AndroidRuntime(638): at dalvik.system.NativeStart.main(Native Method) 04-15 20:50:24.084: E/AndroidRuntime(638): Caused by: android.database.sqlite.SQLiteException: no such column: website (code 1): , while compiling: SELECT _id, business, address, phone, hours, website FROM Business 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteQuery.&lt;init&gt;(SQLiteQuery.java:37) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200) 04-15 20:50:24.084: E/AndroidRuntime(638): at com.example.database.MainActivity.getAllTitles(MainActivity.java:101) 04-15 20:50:24.084: E/AndroidRuntime(638): at com.example.database.DBUse.onCreate(DBUse.java:19) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.app.Activity.performCreate(Activity.java:5008) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 04-15 20:50:24.084: E/AndroidRuntime(638): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 04-15 20:50:24.084: E/AndroidRuntime(638): ... 11 more </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