新的android开发,请温和哈哈。我想用我的SQLite数据库中的数据填充微调器。我有一个预填充的表,并且能够成功查询它。问题是我能够在我的emulater(android 2.2)中运行它时填充微调器,但无法在我的便携式设备(平板电脑和手机)上运行(运行android 2.2)。我收到一条通用的错误消息:“applilcation ...(app name)...意外停止,请重试。”不过,我注意到,在我的模拟器中,它的构建路径被设置为“Android 2.2”,但当我将其更改为Google API(2.2平台)时,它会运行得非常好,然后就会遇到它。我错过了什么?这里正在使用的代码填充微调控制:在Android谷歌API(2.2平台)中运行时的问题
final DBAdapter db = new DBAdapter(this);
db.open();
Cursor c = db.getAllStates();
startManagingCursor(c);
String[] columns = new String[]{DBAdapter.KEY_STATE_NAME};
int[] to = new int []{android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, columns, to);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//get reference to the spinner...
Spinner s =(Spinner) findViewById(R.id.spinner_state);
s.setAdapter(adapter);
db.close();
这里是我的代码来获取数据:
public Cursor getAllStates()
{
Cursor c = null;
c = db.query(DATABASE_TABLE_STATE, new String[] { KEY_STATE_ID, KEY_STATE_NAME }, null, null, null, null, null);
//c = db.rawQuery("select * from tblStates", null);
return c;
}
LocCat:
: INFO/Database(305): sqlite returned: error code = 1, msg = no such table: tblStates
: DEBUG/AndroidRuntime(305): Shutting down VM
: WARN/dalvikvm(305): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
: ERROR/AndroidRuntime(305): FATAL EXCEPTION: main
: ERROR/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{king.chad.SDE/king.chad.SDE.BuildingAddressActivity}
: android.database.sqlite.SQLiteException: no such table: tblStates: , while compiling: SELECT _id, stateName FROM tblStates
: ERROR/AndroidRuntime(305): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
请问您可以向我们提供stackstrace(可以在Logcat中找到(在DDMS中)) –
添加了locat错误消息,但是当运行相同的代码并将build path设置为Android时没有任何意义2.2它的工作原理和将其更改为Google API(2.2平台)时不会... – cking24343
好的,它所引用的数据库是旧版本,缺少表格。我删除了它,并将它添加回最新的一个,它适用于模拟器。但仍然无法使用我的设备。 – cking24343