Java 应用程序在向微调器填充数据时停止响应。怎么了?
我添加这段代码是为了从数据库中获取微调器项目的数据:Java 应用程序在向微调器填充数据时停止响应。怎么了?,java,android,database,spinner,fill,Java,Android,Database,Spinner,Fill,我添加这段代码是为了从数据库中获取微调器项目的数据: SRSSQLiteHelper datahelper = new SRSSQLiteHelper(getApplicationContext()); Set<String> allEvents = datahelper.getAllEvents(datahelper.getReadableDatabase()); ArrayAdapter<String> spinnerAdapter
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;
}
在上次改变之前,一切都很顺利。没有错误日志,应用程序只是停止响应。有什么不对劲吗?因为你从不增加i,而cursor.moveToPositioni是一个无限循环。哦,我是个白痴,谢谢:-