【发布时间】:2014-06-24 07:17:27
【问题描述】:
我已经在论坛中搜索了类似的问题,据我所知,我正在按照其他解决方案建议的方式进行操作,但我仍然收到错误 “您的内容必须有一个 id 属性为 android 的列表视图.r.id.list"
我的 MainActivity.java 看起来像:
public class MainActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
new ArrayList<String>()));
}
我的activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="dk.beatpro.mibfinder.MainActivity"
tools:ignore="MergeRootFrame" />
还有fragment_mail.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="dk.beatpro.mibfinder.MainActivity$PlaceholderFragment" >
<Button
android:id="@+id/button_findMIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_findMIB" />
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button_findMIB" />
</RelativeLayout>
但我收到以下运行时错误:
06-24 09:00:07.726: E/AndroidRuntime(10542): FATAL EXCEPTION: main
06-24 09:00:07.726: E/AndroidRuntime(10542): Process: dk.beatpro.mibfinder, PID: 10542
06-24 09:00:07.726: E/AndroidRuntime(10542): java.lang.RuntimeException: Unable to start activity ComponentInfo{dk.beatpro.mibfinder/dk.beatpro.mibfinder.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
即使我有 android:id="@android:id/list" 用于 <ListView\> 元素。
谁能告诉我这里缺少什么?
【问题讨论】:
标签: android listview android-listview runtime-error