0

我有一个我无法解决的错误。我已经做了好几个小时了,我所看到的任何地方都给了我同样的回应。

所以这是我调用活动的方法:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Fragment fragment;
    FragmentManager fm = getSupportFragmentManager();
    switch (item.getItemId()) {
        case R.id.action_add:
            actionBar.hide();
            Toast.makeText(this, "Let's add a dream", Toast.LENGTH_SHORT)
                    .show();

            fragment = new addDreamFragment();
            fm.beginTransaction()
                    .replace(R.id.container, fragment)
                    .commit();
            break;

        case R.id.action_view:
        Toast.makeText(this, "Let's see those dreams...", Toast.LENGTH_SHORT)
                .show();
        Intent i = new Intent(MainActivity.this, DreamListActivity.class);
        startActivity(i);
        break;
        case R.id.action_share:
            Toast.makeText(this, "Menu item 2 selected", Toast.LENGTH_SHORT)
                    .show();
            break;

        default:
            break;
    }
    actionBar.show();
    return true;
}

它从 FragmentActivity 调用到 ListActivity。

这是我继续收到的错误:

06-23 09:02:54.033: ERROR/AndroidRuntime(2035): FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{swin.examples.cloud/swin.examples.cloud.DreamListActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

我有三个 xml 文件,一个用于 main,一个用于 listactivity,另一个用于生成列表适配器。有人可以帮我吗?另外,我也想从片段内部开始列表活动,也将不胜感激在完成这项工作方面的一些帮助!

XML 文件一:片段活动的主要布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/container" />

XML 文件二:ListActivity 的布局:编辑器很奇怪,没有显示它。这只是一个 FrameLayout 声明。

XML 文件三:列表视图

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/text"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5sp"
    android:textSize="25sp" >

<!--Creates the row for the ListAdapter in the ListActivity. -->

    <ListView
        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/android:empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_dreams" />

</TextView>
4

1 回答 1

0

我发现了错误。我需要重新排列 xml 文件中的对象。现在一切都解决了。谢谢您的帮助。

于 2013-06-24T12:49:34.050 回答