应用程序意外停止。单击按钮后出现强制关闭

时间:2012-07-23 08:50:00

标签: android-emulator

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

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)

1 个答案:

答案 0 :(得分:0)

您的异常堆栈显示错误是由于表(peopletable)不存在而导致的。

快速浏览一下代码即可显示以下内容:

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

错误可能是由于代码中的拼写错误造成的。您在代码中使用的是DATABASE_NAME而不是DATABASE_TABLE,因此您的表名与其他代码所期望的名称不同。