0

应用程序意外停止。强制关闭。单击“更新”按钮后,此消息仅针对一个意图,对于另一个意图,该应用程序可以正常工作。该应用程序将获取两个字符串输入并将它们更新到数据库并查看表。我的应用程序正在完美更新,但是当我单击查看它时出现错误消息。

public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    db.execSQL("CREATE TABLE " + DATABASE_NAME + "(" +
            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) {
    // TODO Auto-generated method stub
    db.execSQL("DROP TABLE IF EXISTS " + DATABASE_NAME);
    onCreate(db);
}

}

public hotornot(Context c){
ourcontext = c;
}
public hotornot open(){
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() {
// TODO Auto-generated method stub
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;
}
}

这是更新的清单文件:

07-24 17:31:05.134: ERROR/AndroidRuntime(203): Uncaught handler: thread main exiting      due to uncaught exception
07-24 17:31:05.164: ERROR/AndroidRuntime(203): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=org.sqlite.SVIEW }
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.app.Activity.startActivityForResult(Activity.java:2749)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.app.Activity.startActivity(Activity.java:2855)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at org.sqlite.sqliteexample.onClick(sqliteexample.java:75)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.view.View.performClick(View.java:2364)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.view.View.onTouchEvent(View.java:4179)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.widget.TextView.onTouchEvent(TextView.java:6541)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.view.View.dispatchTouchEvent(View.java:3709)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.os.Looper.loop(Looper.java:123)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at android.app.ActivityThread.main(ActivityThread.java:4363)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at java.lang.reflect.Method.invokeNative(Native Method)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at java.lang.reflect.Method.invoke(Method.java:521)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
07-24 17:31:05.164: ERROR/AndroidRuntime(203):     at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

0

Your exception stack shows that the error is due to the table (peopletable) not being present.

A quick glance at your code shows the following:

db.execSQL("CREATE TABLE " + DATABASE_NAME + "(" + KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT NOT NULL, " + KEY_HOTNESS + " TEXT NOT NULL);"

The error is probably due to a typo in your code. You are using DATABASE_NAME instead of DATABASE_TABLE in your code, as a result of which your table name is different from the one that the rest of your code is expecting.

于 2012-07-24T03:39:53.370 回答