我添加了这段代码,以便从数据库中为微调器项目获取数据:
SRSSQLiteHelper datahelper = new SRSSQLiteHelper(getApplicationContext());
Set<String> allEvents = datahelper.getAllEvents(datahelper.getReadableDatabase());
ArrayAdapter<String> spinnerAdapter= new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, (java.util.List<String>) allEvents);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(spinnerAdapter);
以下是从数据库中提取数据的getAllEvents方法:
public Set<String> getAllEvents(SQLiteDatabase db) {
Set<String> allEvents = new HashSet<String>();
Cursor cursor = db.rawQuery("SELECT * FROM SRSEvents", null);
int i=0;
while (cursor.moveToPosition(i)) { allEvents.add(cursor.getString(3)); }
return allEvents;
}
在最后一次改变之前一切正常。没有错误日志,应用程序只是停止响应。什么可能是错的?