【发布时间】:2012-01-25 19:31:44
【问题描述】:
我关注了this tutorial,但是当我尝试运行应用程序时,我得到了Unfortunately HelloListView has stopped
IDE 不会给出警告或错误。
我的 HelloViewListActivity.java 看起来像这样:
public class HelloListViewActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] countries = getResources().getStringArray(R.array.countries_array);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, countries));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),
((TextView) view).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
我的strings.xml 和list_item.xml 都是identical to the tutorial.
Logcat log here 我到底做错了什么?
【问题讨论】:
-
您的 list_content_simple.xml 似乎不正确。再验证一次。
-
@thinksteep list_content_simple.xml 没有在教程中提到。我确实找到了 SDK 文件夹并将其添加到我的 res/layout 但仍然是同样的错误。
-
您所指的教程有点零散。现在看看我的回答。我已经包含了工作示例教程的链接,如果你不想要,你可以忽略数据库部分。
-
使用logcat 获取有关崩溃的更多信息。或者在设备上,使用市场上的 Catlog 应用程序。