2012-04-29 25 views
3

我是一個初學者的Android開發,我遵循教程thenewboston網站的學習。但我不明白爲什麼代碼不能在那裏工作,當我檢查我的數據庫的創建時,我沒有看到任何奇怪的東西。你能幫我嗎?我會很樂意瞭解這些錯誤,並繼續我在android開發方面的學習。需要幫助的Android上的SQLite,從教程的新波士頓

當我啓動我的AVD和我點擊更新我有「finnaly」「好」,但也有一個記錄的錯誤。當我點擊視圖查看我的數據時,彈出一個對話框,其中包含消息「不幸的是,SQLiteExample已停止」

對不起,很長的文章,但就像我是一個開墾者我給你所有的代碼,我可以給你。

SQLiteExample.java

package exercice.thenewboston; 

import android.app.Activity; 
import android.app.Dialog; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class SQLiteExample extends Activity implements OnClickListener 
{ 
    Button sqlUpdate, sqlView; 
    EditText sqlName, sqlHotness; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     sqlUpdate = (Button) findViewById(R.id.bSQLUpdate); 
     sqlName = (EditText) findViewById(R.id.etSQLName); 
     sqlHotness = (EditText) findViewById(R.id.etSQLHotness); 

     sqlView = (Button) findViewById(R.id.bSQLopenView); 
     sqlView.setOnClickListener(this); 
     sqlUpdate.setOnClickListener(this); 
    } 

    public void onClick(View arg0){ 
     switch (arg0.getId()) 
     { 
      case R.id.bSQLUpdate: 

      boolean didItWork = true; 
      try 
      { 
       String name = sqlName.getText().toString(); 
       String hotness = sqlHotness.getText().toString(); 

       HotOrNot entry = new HotOrNot(SQLiteExample.this); 
       entry.open(); 
       entry.createEntry(name, hotness); 
       entry.close(); 
      } 
      catch(Exception e) 
      { 
       didItWork = false; 
       String error = e.toString(); 
       Dialog d = new Dialog(this); 
       d.setTitle("CATCH"); 
       TextView tv = new TextView(this); 
       tv.setText(error); 
       d.setContentView(tv); 
       d.show(); 
      } 

      finally 
      { 
       if (didItWork) 
       { 
        Dialog d = new Dialog(this); 
        d.setTitle("FINALLY"); 
        TextView tv = new TextView(this); 
        tv.setText("GOOD"); 
        d.setContentView(tv); 
        d.show(); 
       } 
      } 
      break; 
      case R.id.bSQLopenView: 
       Intent i = new Intent("exercice.thenewboston.SQLVIEW"); 
       startActivity(i); 
      break; 
     } 
    } 
    } 

HotOrNot.java

package exercice.thenewboston; 

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; 

public class HotOrNot 
{ 
    public static final String KEY_ROWID   = "_id"; 
    public static final String KEY_NAME   = "persons_name"; 
    public static final String KEY_HOTNESS   = "persons_hotness"; 

    private static final String DATABASE_NAME  = "HotOrNotdb"; 
    private static final String DATABASE_TABLE  = "peopleTable"; 
    private static final int DATABASE_VERSION = 1; 

    private DbHelper   ourHelper; 
    private final Context  ourContext; 
    private SQLiteDatabase  ourDatabase; 

    private static class DbHelper extends SQLiteOpenHelper 
    { 

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

     @Override 
     public void onCreate(SQLiteDatabase db) 
     { 
      db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_HOTNESS + " TEXT NOT NULL);"); 
     } 

     @Override 
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
     { 
      db.execSQL("DROP TABLE IF EXITS " + DATABASE_TABLE); 
      onCreate(db); 
     } 
    } 

    public HotOrNot(Context c) 
    { 
     ourContext = c; 
    } 

    public HotOrNot open() throws SQLException 
    { 
     ourHelper = new DbHelper(ourContext); 
     ourDatabase = ourHelper.getWritableDatabase(); 
     return this; 
    } 

    public void close() 
    { 
     ourHelper.close(); 
    } 

    public long createEntry(String name, String hotness) 
    { 
     ContentValues cv = new ContentValues(); 
     cv.put(KEY_NAME, name); 
     cv.put(KEY_HOTNESS, hotness); 
     return ourDatabase.insert(DATABASE_TABLE, null, cv); 
    } 

    public String getData() 
    { 
     String[] columns = new String[]{ KEY_ROWID, KEY_NAME, KEY_HOTNESS}; 
     Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null); 
     String result = ""; 

     int iRow = c.getColumnIndex(KEY_ROWID); 
     int iName = c.getColumnIndex(KEY_NAME); 
     int iHotness = c.getColumnIndex(KEY_HOTNESS); 

     for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) 
     { 
      result = result + c.getString(iRow) + " " + c.getString(iName) + " " + c.getString(iHotness) + "\n"; 
     } 

     return result; 

    } 
} 

SQLView.java

package exercice.thenewboston; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

public class SQLView extends Activity{ 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.sqlview); 
     TextView tv = (TextView) findViewById(R.id.tvSQLinfo); 
     HotOrNot info = new HotOrNot(this); 
     info.open(); 
     String data = info.getData(); 
     info.close(); 
     tv.setText(data); 
    } 
} 

RES - >佈局 - > main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/TextView1" 
     android:text="Name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

    </TextView> 

    <EditText 
     android:id="@+id/etSQLName" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

    </EditText> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hotness scale 1 to 10"> 
    </TextView> 

    <EditText 
     android:id="@+id/etSQLHotness" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

    </EditText> 

    <Button 
     android:id="@+id/bSQLUpdate" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Update SQLite Database" /> 


    <Button 
     android:id="@+id/bSQLopenView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="View"> 

    </Button> 

</LinearLayout> 

水庫 - >佈局 - > sqlview.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id= "@+id/tableLayout1"> 

     <TableRow> 
      <TextView android:text="Names" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="1"> 
      </TextView> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="Hotness" 
       android:layout_weight="1"> 
      </TextView> 

     </TableRow> 

    </TableLayout> 

    <TextView 
     android:id="@+id/tvSQLinfo" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:text="get info from db"> 
    </TextView> 

</LinearLayout> 

日誌當我啓動,然後把DATAS在田間,點擊更新,然後點擊查看後

04-29 16:01:58.217: I/dalvikvm(530): threadid=3: reacting to signal 3 
04-29 16:01:58.277: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt' 
04-29 16:01:58.627: D/gralloc_goldfish(530): Emulator without GPU emulation detected. 
04-29 16:01:58.737: I/dalvikvm(530): threadid=3: reacting to signal 3 
04-29 16:01:58.757: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt' 
04-29 16:02:20.867: I/SqliteDatabaseCpp(530): sqlite returned: error code = 1, msg = table peopleTable has no column named persons_hotness, db=/data/data/exercice.thenewboston/databases/HotOrNotdb 
04-29 16:02:20.945: E/SQLiteDatabase(530): Error inserting persons_hotness=4 persons_name=rt 
04-29 16:02:20.945: E/SQLiteDatabase(530): android.database.sqlite.SQLiteException: table peopleTable has no column named persons_hotness: , while compiling: INSERT INTO peopleTable(persons_hotness,persons_name) VALUES (?,?) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:112) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1591) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at exercice.thenewboston.HotOrNot.createEntry(HotOrNot.java:69) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at exercice.thenewboston.SQLiteExample.onClick(SQLiteExample.java:46) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.view.View.performClick(View.java:3511) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.view.View$PerformClick.run(View.java:14105) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.os.Handler.handleCallback(Handler.java:605) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.os.Handler.dispatchMessage(Handler.java:92) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.os.Looper.loop(Looper.java:137) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at android.app.ActivityThread.main(ActivityThread.java:4424) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at java.lang.reflect.Method.invokeNative(Native Method) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at java.lang.reflect.Method.invoke(Method.java:511) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
04-29 16:02:20.945: E/SQLiteDatabase(530): at dalvik.system.NativeStart.main(Native Method) 
04-29 16:02:26.688: I/SqliteDatabaseCpp(530): sqlite returned: error code = 1, msg = no such column: persons_hotness, db=/data/data/exercice.thenewboston/databases/HotOrNotdb 
04-29 16:02:26.698: D/AndroidRuntime(530): Shutting down VM 
04-29 16:02:26.698: W/dalvikvm(530): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 
04-29 16:02:26.848: E/AndroidRuntime(530): FATAL EXCEPTION: main 
04-29 16:02:26.848: E/AndroidRuntime(530): java.lang.RuntimeException: Unable to start activity ComponentInfo{exercice.thenewboston/exercice.thenewboston.SQLView}: android.database.sqlite.SQLiteException: no such column: persons_hotness: , while compiling: SELECT _id, persons_name, persons_hotness FROM peopleTable 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.app.ActivityThread.access$600(ActivityThread.java:123) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.os.Handler.dispatchMessage(Handler.java:99) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.os.Looper.loop(Looper.java:137) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.app.ActivityThread.main(ActivityThread.java:4424) 
04-29 16:02:26.848: E/AndroidRuntime(530): at java.lang.reflect.Method.invokeNative(Native Method) 
04-29 16:02:26.848: E/AndroidRuntime(530): at java.lang.reflect.Method.invoke(Method.java:511) 
04-29 16:02:26.848: E/AndroidRuntime(530): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
04-29 16:02:26.848: E/AndroidRuntime(530): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
04-29 16:02:26.848: E/AndroidRuntime(530): at dalvik.system.NativeStart.main(Native Method) 
04-29 16:02:26.848: E/AndroidRuntime(530): Caused by: android.database.sqlite.SQLiteException: no such column: persons_hotness: , while compiling: SELECT _id, persons_name, persons_hotness FROM peopleTable 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1485) 
04-29 16:02:26.848: E/AndroidRuntime(530): at exercice.thenewboston.HotOrNot.getData(HotOrNot.java:75) 
04-29 16:02:26.848: E/AndroidRuntime(530): at exercice.thenewboston.SQLView.onCreate(SQLView.java:17) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.app.Activity.performCreate(Activity.java:4465) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
04-29 16:02:26.848: E/AndroidRuntime(530): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
04-29 16:02:26.848: E/AndroidRuntime(530): ... 11 more 
04-29 16:02:27.018: I/dalvikvm(530): threadid=3: reacting to signal 3 
04-29 16:02:27.238: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt' 
04-29 16:02:27.338: D/dalvikvm(530): GC_CONCURRENT freed 238K, 6% free 6678K/7047K, paused 19ms+5ms 
04-29 16:02:27.388: E/SQLiteDatabase(530): close() was never explicitly called on database '/data/data/exercice.thenewboston/databases/HotOrNotdb' 
04-29 16:02:27.388: E/SQLiteDatabase(530): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1943) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1007) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1051) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:770) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at exercice.thenewboston.HotOrNot.open(HotOrNot.java:55) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at exercice.thenewboston.SQLView.onCreate(SQLView.java:16) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.app.Activity.performCreate(Activity.java:4465) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.app.ActivityThread.access$600(ActivityThread.java:123) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.os.Handler.dispatchMessage(Handler.java:99) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.os.Looper.loop(Looper.java:137) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at android.app.ActivityThread.main(ActivityThread.java:4424) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at java.lang.reflect.Method.invokeNative(Native Method) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at java.lang.reflect.Method.invoke(Method.java:511) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
04-29 16:02:27.388: E/SQLiteDatabase(530): at dalvik.system.NativeStart.main(Native Method) 
04-29 16:02:27.527: I/dalvikvm(530): threadid=3: reacting to signal 3 
04-29 16:02:27.537: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt' 
04-29 16:02:27.837: I/dalvikvm(530): threadid=3: reacting to signal 3 
04-29 16:02:27.857: I/dalvikvm(530): Wrote stack traces to '/data/anr/traces.txt' 
04-29 16:02:29.787: I/Process(530): Sending signal. PID: 530 SIG: 9 

我希望你的幫助, 關心。

更多詳細信息: 回答SAM 感謝您的回覆Sam。 所以我把DATABASE_VERSION = 2; 20

@Override 
public void onCreate(SQLiteDatabase db) 
{ 
db.execSQL("DROP TABLE IF EXITS " + DATABASE_TABLE); // same error if i remove this line 

db.execSQL("CREATE TABLE peopleTable (_id INTEGER PRIMARY KEY AUTOINCREMENT, persons_name TEXT NOT NULL, persons_hotness TEXT NOT NULL);"); 
} 

消息在Android上,當我點擊更新錯誤 「抓android.database.sqlite.SQLiteException:近 」退出「:語法錯誤:在編譯:DROP TABLE如果退出peopleTable」

04-29 19:11:50.361: W/dalvikvm(536): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 
04-29 19:11:50.441: E/AndroidRuntime(536): FATAL EXCEPTION: main 
04-29 19:11:50.441: E/AndroidRuntime(536): java.lang.RuntimeException: Unable to start activity ComponentInfo{exercice.thenewboston/exercice.thenewboston.SQLView}: android.database.sqlite.SQLiteException: near "EXITS": syntax error: , while compiling: DROP TABLE IF EXITS peopleTable 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.app.ActivityThread.access$600(ActivityThread.java:123) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.os.Handler.dispatchMessage(Handler.java:99) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.os.Looper.loop(Looper.java:137) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.app.ActivityThread.main(ActivityThread.java:4424) 
04-29 19:11:50.441: E/AndroidRuntime(536): at java.lang.reflect.Method.invokeNative(Native Method) 
04-29 19:11:50.441: E/AndroidRuntime(536): at java.lang.reflect.Method.invoke(Method.java:511) 
04-29 19:11:50.441: E/AndroidRuntime(536): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
04-29 19:11:50.441: E/AndroidRuntime(536): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
04-29 19:11:50.441: E/AndroidRuntime(536): at dalvik.system.NativeStart.main(Native Method) 
04-29 19:11:50.441: E/AndroidRuntime(536): Caused by: android.database.sqlite.SQLiteException: near "EXITS": syntax error: , while compiling: DROP TABLE IF EXITS peopleTable 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:134) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:84) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1899) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1839) 
04-29 19:11:50.441: E/AndroidRuntime(536): at exercice.thenewboston.HotOrNot$DbHelper.onUpgrade(HotOrNot.java:44) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:170) 
04-29 19:11:50.441: E/AndroidRuntime(536): at exercice.thenewboston.HotOrNot.open(HotOrNot.java:57) 
04-29 19:11:50.441: E/AndroidRuntime(536): at exercice.thenewboston.SQLView.onCreate(SQLView.java:16) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.app.Activity.performCreate(Activity.java:4465) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
04-29 19:11:50.441: E/AndroidRuntime(536): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
04-29 19:11:50.441: E/AndroidRuntime(536): ... 11 more 
04-29 19:11:50.691: I/dalvikvm(536): threadid=3: reacting to signal 3 
04-29 19:11:50.711: I/dalvikvm(536): Wrote stack traces to '/data/anr/traces.txt' 
04-29 19:11:51.071: I/dalvikvm(536): threadid=3: reacting to signal 3 
04-29 19:11:51.111: I/dalvikvm(536): Wrote stack traces to '/data/anr/traces.txt' 

回答

1

你的創建語句看起來很好,所以我猜想你有沒有改變你的表格設計。嘗試刪除舊錶並創建新的模式。最簡單的方法是將您的DATABASE_VERSION升級到2.

+0

我已經在我的第一篇文章中回答了您的問題(我無法在這裏回答,因爲日誌對於評論中允許的字符數量如此之大 – user1364282

+0

如果你還沒有找到它,你需要將'EXITS'更改爲'EXISTS'。 – Sam

+0

感謝您的錯誤山姆!我沒有看到它,這個+ database_version和工程! 非常感謝:) 只是一個問題。沒有AVD的地方可以看到我的數據庫嗎?看看我的數據等 – user1364282