我是android developpemment的初学者,我按照 thenewboston 网站的教程进行学习。但我不明白为什么代码不能在那里工作,当我检查我的数据库的创建时,我看到没什么奇怪的。你能帮我吗?我很乐意理解这些错误并继续学习android developpement。
当我启动我的avd并且我点击更新时,我有“finnaly”“good”但是还记录了一个错误。当我点击视图查看我的数据时,弹出一个对话框,显示消息“不幸的是,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>
res - &gt;布局 - &gt; 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>
我启动时记录,然后将数据放入fied,点击更新并点击视图后
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);");
}
当我点击更新“Catch.android.database.sqlite.SQLiteException:Near”EXITS“时,android上的消息错误:语法错误:编译时:DROP表如果EXITS 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'
答案 0 :(得分:1)
你的创建语句看起来很好,所以我猜你有没有在某些时候改变你的表格设计。尝试删除旧表并创建新架构。最简单的方法是将DATABASE_VERSION
升级到2.