总是得到android.database.sqlite.SQLiteException:near" Time"在运行SQLite时

时间:2014-11-03 22:25:41

标签: javascript android sqlite

我已经在这里尝试了关于' android.database.sqlite.SQLiteException'的所有各种建议。我仍然一直在收到错误。每次我尝试运行应用程序时,它都会崩溃,这是由该异常引起的。我已经阅读了大约10次的每一行,仍然无法找到错误。请帮助,我真的很感激。

EventHandler类

package com.team11.healthdb;

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.util.Log;

public class EventHandler extends SQLiteOpenHelper {

// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "HealthTracker";

public EventHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
    //SQL Statement to create TABLE_EVENTS
    String CREATE_TABLE_EVENTS = "CREATE TABLE TABLE_EVENTS ( "
            + "KEY_ID INTEGER PRIMARY KEY AUTOINCREMENT, "
            + "KEY_TITLE TEXT, " + "KEY_DESCRIPTION TEXT, "
            + "KEY_START INTEGER, " + "KEY_END INTEGER, "
            + "KEY_LOCATION TEXT )";

    // Creates TABLE_EVENTS
    db.execSQL(CREATE_TABLE_EVENTS);
}

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS TABLE_EVENTS");

    // Creates fresh table
    this.onCreate(db);
}

//-------------------------------------------------------------------------
/**
 * All CRUD(Create, Read, Update, Delete) Operations
 */
// Events table name
private static final String TABLE_EVENTS = "EVENTS";

// Events Table Columns names
private static final String KEY_ID = "ID";
private static final String KEY_TITLE = "Title";
private static final String KEY_DESCRIPTION = "Description";
private static final String KEY_START = "Start Time";
private static final String KEY_END = "End Time";
private static final String KEY_LOCATION = "Location";

private static final String[] COLUMNS = {KEY_ID,KEY_TITLE,KEY_DESCRIPTION,KEY_START,KEY_END,KEY_LOCATION};

// Adding new contact
public void addEvent(Event event) {
    Log.d("addEvent", event.toString());

    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, event.getTitle()); // Event Title
    values.put(KEY_DESCRIPTION, event.getDescription()); // Event Description
    values.put(KEY_START, event.getStart()); // Event Start Time
    values.put(KEY_END, event.getEnd()); // Event End Time
    values.put(KEY_LOCATION, event.getLocation()); // Event Location

    // Inserting Row
    db.insert(TABLE_EVENTS, null, values);
    db.close(); // Closing database connection
}

// Getting single event
public Event getEvent(int id) {
    SQLiteDatabase db = this.getReadableDatabase();

    Cursor cursor = db.query(TABLE_EVENTS, COLUMNS, " KEY_ID = ?",
            new String[] { String.valueOf(id) }, null, null, null, null);
    if (cursor != null)
        cursor.moveToFirst();

    Event event = new Event();
    event.setID(Integer.parseInt(cursor.getString(0)));
    event.setTitle(cursor.getString(1));
    event.setDescription(cursor.getString(2));
    event.setStart(Integer.parseInt(cursor.getString(3)));
    event.setEnd(Integer.parseInt(cursor.getString(4)));
    event.setLocation(cursor.getString(5));

    //log
    Log.d("getEvent("+id+")", event.toString());

    // return contact
    return event;
}

// Getting All Events
public List<Event> getAllEvents() {
    List<Event> events = new ArrayList<Event>();

    // Select All Query
    String query = "SELECT  * FROM " + TABLE_EVENTS;

    // Get reference to writable DB
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(query, null);

    // Go over each row, build book and add it to list
    Event event = null;
    if (cursor.moveToFirst()) {
        do {
            event = new Event();
            event.setID(Integer.parseInt(cursor.getString(0)));
            event.setTitle(cursor.getString(1));
            event.setDescription(cursor.getString(2));
            event.setStart(Integer.parseInt(cursor.getString(3)));
            event.setEnd(Integer.parseInt(cursor.getString(4)));
            event.setLocation(cursor.getString(5));

            // Adding events to list
            events.add(event);
        } while (cursor.moveToNext());
    }

    Log.d("getAllEvents()", events.toString());

    // return contact list
    return events;
}

// Updating single contact
public int updateEvent(Event event) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("KEY_TITLE", event.getTitle()); // Event Title
    values.put("KEY_DESCRIPTION", event.getDescription()); // Event Description
    values.put("KEY_START", event.getStart()); // Event Start Time
    values.put("KEY_END", event.getEnd()); // Event End Time
    values.put("KEY_LOCATION", event.getLocation()); // Event Location

    // updating row
    int i = db.update(TABLE_EVENTS, values, KEY_ID + " = ?", 
            new String[] { String.valueOf(event.getID()) });

    // Close DB
    db.close();
    return i;
}

// Deleting single event
public void deleteEvent(Event event) {
    SQLiteDatabase db = this.getWritableDatabase();

    // Delete
    db.delete(TABLE_EVENTS, KEY_ID + " = ?",
            new String[] { String.valueOf(event.getID()) });

    // Close
    db.close();

    Log.d("deleteEvent", event.toString());
}
}

MainActivity Class

package com.team11.healthdb;

import java.util.List;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    EventHandler db = new EventHandler(this);

    /**
     * CRUD Operations
     * */
    // Inserting Contacts
    Log.d("Insert: ", "Inserting ..");
    db.addEvent(new Event("Headache", "Took Medicine and had side effects", 1015, 1018, "Bedroom"));
    db.addEvent(new Event("Dizzy", "Took Medicine and had side effects", 1520, 1530, "Asda"));
    db.addEvent(new Event("Blackouts", "Took Medicine and had side effects", 1015, 1018, "Tesco"));

    // get all books
    List<Event> list = db.getAllEvents();

    // delete one book
    db.deleteEvent(list.get(0));

    // get all books
    db.getAllEvents();
}
}

这是错误日志:

&#13;
&#13;
11-03 17:05:39.434: I/dalvikvm(1195): Could not find method android.view.ViewGroup.onNestedScrollAccepted, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onNestedScrollAccepted
11-03 17:05:39.434: W/dalvikvm(1195): VFY: unable to resolve virtual method 11388: Landroid/view/ViewGroup;.onNestedScrollAccepted (Landroid/view/View;Landroid/view/View;I)V
11-03 17:05:39.444: D/dalvikvm(1195): VFY: replacing opcode 0x6f at 0x0000
11-03 17:05:39.444: I/dalvikvm(1195): Could not find method android.view.ViewGroup.onStopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.onStopNestedScroll
11-03 17:05:39.444: W/dalvikvm(1195): VFY: unable to resolve virtual method 11394: Landroid/view/ViewGroup;.onStopNestedScroll (Landroid/view/View;)V
11-03 17:05:39.444: D/dalvikvm(1195): VFY: replacing opcode 0x6f at 0x0000
11-03 17:05:39.474: I/dalvikvm(1195): Could not find method android.support.v7.internal.widget.ActionBarOverlayLayout.stopNestedScroll, referenced from method android.support.v7.internal.widget.ActionBarOverlayLayout.setHideOnContentScrollEnabled
11-03 17:05:39.474: W/dalvikvm(1195): VFY: unable to resolve virtual method 8967: Landroid/support/v7/internal/widget/ActionBarOverlayLayout;.stopNestedScroll ()V
11-03 17:05:39.484: D/dalvikvm(1195): VFY: replacing opcode 0x6e at 0x000e
11-03 17:05:39.534: I/dalvikvm(1195): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations
11-03 17:05:39.544: W/dalvikvm(1195): VFY: unable to resolve virtual method 367: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
11-03 17:05:39.544: D/dalvikvm(1195): VFY: replacing opcode 0x6e at 0x0002
11-03 17:05:39.564: I/dalvikvm(1195): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType
11-03 17:05:39.574: W/dalvikvm(1195): VFY: unable to resolve virtual method 389: Landroid/content/res/TypedArray;.getType (I)I
11-03 17:05:39.574: D/dalvikvm(1195): VFY: replacing opcode 0x6e at 0x0002
11-03 17:05:39.874: D/Insert:(1195): Inserting ..
11-03 17:05:39.874: D/addEvent(1195): Event [Event ID: 0, Event Title: Headache, Event Description: Took Medicine and had side effects, Start Time: 1015, End Time: 1018, Location: Bedroom]
11-03 17:05:40.114: E/SQLiteLog(1195): (1) near "Time": syntax error
11-03 17:05:40.154: E/SQLiteDatabase(1195): Error inserting End Time=1018 Start Time=1015 Location=Bedroom Description=Took Medicine and had side effects Title=Headache
11-03 17:05:40.154: E/SQLiteDatabase(1195): android.database.sqlite.SQLiteException: near "Time": syntax error (code 1): , while compiling: INSERT INTO EVENTS(End Time,Start Time,Location,Description,Title) VALUES (?,?,?,?,?)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at com.team11.healthdb.EventHandler.addEvent(EventHandler.java:79)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at com.team11.healthdb.MainActivity.onCreate(MainActivity.java:21)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.app.Activity.performCreate(Activity.java:5231)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.os.Handler.dispatchMessage(Handler.java:102)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.os.Looper.loop(Looper.java:136)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at java.lang.reflect.Method.invokeNative(Native Method)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at java.lang.reflect.Method.invoke(Method.java:515)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-03 17:05:40.154: E/SQLiteDatabase(1195): 	at dalvik.system.NativeStart.main(Native Method)
11-03 17:05:40.164: D/addEvent(1195): Event [Event ID: 0, Event Title: Dizzy, Event Description: Took Medicine and had side effects, Start Time: 1520, End Time: 1530, Location: Asda]
11-03 17:05:40.264: E/SQLiteLog(1195): (1) near "Time": syntax error
11-03 17:05:40.294: E/SQLiteDatabase(1195): Error inserting End Time=1530 Start Time=1520 Location=Asda Description=Took Medicine and had side effects Title=Dizzy
11-03 17:05:40.294: E/SQLiteDatabase(1195): android.database.sqlite.SQLiteException: near "Time": syntax error (code 1): , while compiling: INSERT INTO EVENTS(End Time,Start Time,Location,Description,Title) VALUES (?,?,?,?,?)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at com.team11.healthdb.EventHandler.addEvent(EventHandler.java:79)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at com.team11.healthdb.MainActivity.onCreate(MainActivity.java:22)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.app.Activity.performCreate(Activity.java:5231)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.os.Handler.dispatchMessage(Handler.java:102)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.os.Looper.loop(Looper.java:136)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at java.lang.reflect.Method.invokeNative(Native Method)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at java.lang.reflect.Method.invoke(Method.java:515)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-03 17:05:40.294: E/SQLiteDatabase(1195): 	at dalvik.system.NativeStart.main(Native Method)
11-03 17:05:40.294: D/addEvent(1195): Event [Event ID: 0, Event Title: Blackouts, Event Description: Took Medicine and had side effects, Start Time: 1015, End Time: 1018, Location: Tesco]
11-03 17:05:40.354: E/SQLiteLog(1195): (1) near "Time": syntax error
11-03 17:05:40.404: E/SQLiteDatabase(1195): Error inserting End Time=1018 Start Time=1015 Location=Tesco Description=Took Medicine and had side effects Title=Blackouts
11-03 17:05:40.404: E/SQLiteDatabase(1195): android.database.sqlite.SQLiteException: near "Time": syntax error (code 1): , while compiling: INSERT INTO EVENTS(End Time,Start Time,Location,Description,Title) VALUES (?,?,?,?,?)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at com.team11.healthdb.EventHandler.addEvent(EventHandler.java:79)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at com.team11.healthdb.MainActivity.onCreate(MainActivity.java:23)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.app.Activity.performCreate(Activity.java:5231)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.os.Handler.dispatchMessage(Handler.java:102)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.os.Looper.loop(Looper.java:136)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at java.lang.reflect.Method.invokeNative(Native Method)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at java.lang.reflect.Method.invoke(Method.java:515)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-03 17:05:40.404: E/SQLiteDatabase(1195): 	at dalvik.system.NativeStart.main(Native Method)
11-03 17:05:40.524: E/SQLiteLog(1195): (1) no such table: EVENTS
11-03 17:05:40.544: D/AndroidRuntime(1195): Shutting down VM
11-03 17:05:40.544: W/dalvikvm(1195): threadid=1: thread exiting with uncaught exception (group=0xb3a97ba8)
11-03 17:05:40.644: E/AndroidRuntime(1195): FATAL EXCEPTION: main
11-03 17:05:40.644: E/AndroidRuntime(1195): Process: com.team11.healthdb, PID: 1195
11-03 17:05:40.644: E/AndroidRuntime(1195): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.team11.healthdb/com.team11.healthdb.MainActivity}: android.database.sqlite.SQLiteException: no such table: EVENTS (code 1): , while compiling: SELECT  * FROM EVENTS
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.os.Handler.dispatchMessage(Handler.java:102)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.os.Looper.loop(Looper.java:136)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at java.lang.reflect.Method.invokeNative(Native Method)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at java.lang.reflect.Method.invoke(Method.java:515)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at dalvik.system.NativeStart.main(Native Method)
11-03 17:05:40.644: E/AndroidRuntime(1195): Caused by: android.database.sqlite.SQLiteException: no such table: EVENTS (code 1): , while compiling: SELECT  * FROM EVENTS
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1253)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at com.team11.healthdb.EventHandler.getAllEvents(EventHandler.java:116)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at com.team11.healthdb.MainActivity.onCreate(MainActivity.java:26)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.app.Activity.performCreate(Activity.java:5231)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
11-03 17:05:40.644: E/AndroidRuntime(1195): 	... 11 more
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

避免使用字段名称中的空格。改变你的行

private static final String KEY_START = "Start Time";
private static final String KEY_END = "End Time";

通过

private static final String KEY_START = "Start_Time";
private static final String KEY_END = "End_Time";

该行

11-03 17:05:40.154: E/SQLiteDatabase(1195): android.database.sqlite.SQLiteException: near "Time": syntax error (code 1): , while compiling: INSERT INTO EVENTS(End Time,Start Time,Location,Description,Title) VALUES (?,?,?,?,?)

通常是了解情况发生的关键。