Android 活性大的片段

Android 活性大的片段,android,android-fragments,Android,Android Fragments,我从这个链接()下载了这个基本片段的示例!它非常完美,在平板电脑上比在手机上更有效。但当我在另一个项目上实施的那一刻,电话就响了。。。当它应该在大屏幕上打开xml文件时,应用程序将在启动时崩溃!解决?我丢了什么?谢谢大家! java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chiari.nicola.myapplication/com.chiari.nicola.myapplication.Main

我从这个链接()下载了这个基本片段的示例!它非常完美,在平板电脑上比在手机上更有效。但当我在另一个项目上实施的那一刻,电话就响了。。。当它应该在大屏幕上打开xml文件时,应用程序将在启动时崩溃!解决?我丢了什么?谢谢大家!

java.lang.RuntimeException: Unable to start activity    ComponentInfo{com.chiari.nicola.myapplication/com.chiari.nicola.myapplication.MainActivity_list}: android.view.InflateException: Binary XML file line #23: Error inflating class fragment
这是一节课

public class HeadlinesFragment extends ListFragment {

String[] Headlines = {
        "Article One",
        "Article Two",
        "Article 3",
        "Article 4",
        "Article 5",
        "Article 6",
};

SearchView search_view;



OnHeadlineSelectedListener mCallback;

String[] menutitles;
TypedArray menuIcons;

CustomAdapter adapter;
private List<RowItem> rowItems;

// The container Activity must implement this interface so the frag can deliver messages
public interface OnHeadlineSelectedListener {
    /** Called by HeadlinesFragment when a list item is selected */
    public void onArticleSelected(int position);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // We need to use a different list item layout for devices older than Honeycomb
    int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
            android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1;

    return inflater.inflate(R.layout.list_fragment, null, false);











}

@Override
public void onActivityCreated(Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);

    menutitles = getResources().getStringArray(R.array.titles);
    menuIcons = getResources().obtainTypedArray(R.array.icons);

    rowItems = new ArrayList<RowItem>();

    for (int i = 0; i < menutitles.length; i++) {
        RowItem items = new RowItem(menutitles[i], menuIcons.getResourceId(
                i, -1));

        rowItems.add(items);
    }

    adapter = new CustomAdapter(getActivity(), rowItems);
    setListAdapter(adapter);




}




@Override
public void onStart() {
    super.onStart();

    // When in two-pane layout, set the listview to highlight the selected list item
    // (We do this during onStart because at the point the listview is available.)
    if (getFragmentManager().findFragmentById(R.id.article_fragment) != null) {
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }
}

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);

    // This makes sure that the container activity has implemented
    // the callback interface. If not, it throws an exception.
    try {
        mCallback = (OnHeadlineSelectedListener) activity;
    } catch (ClassCastException e) {
        throw new ClassCastException(activity.toString()
                + " must implement OnHeadlineSelectedListener");
    }
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // Notify the parent activity of selected item
    mCallback.onArticleSelected(position);

    // Set the item as checked to be highlighted when in two-pane layout
    getListView().setItemChecked(position, true);
}
}`

大型xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment android:name="com.example.android.fragments.HeadlinesFragment"
          android:id="@+id/headlines_fragment"
          android:layout_weight="1"
          android:layout_width="0dp"
          android:layout_height="match_parent" />

<fragment android:name="com.example.android.fragments.ArticleFragment"
          android:id="@+id/article_fragment"
          android:layout_weight="2"
          android:layout_width="0dp"
          android:layout_height="match_parent" />

</LinearLayout>

普通xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
tools:context=".HeadlinesFragment" >



<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/fragment_container">






</FrameLayout>

</LinearLayout>

程序包名称错误。 检查您的类HeadlinesFragment所在的包

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment android:name="com.chiari.nicola.myapplication.HeadlinesFragment"
      android:id="@+id/headlines_fragment"
      android:layout_weight="1"
      android:layout_width="0dp"
      android:layout_height="match_parent" />

   <fragment android:name="com.chiari.nicola.myapplication.ArticleFragment"
      android:id="@+id/article_fragment"
      android:layout_weight="2"
      android:layout_width="0dp"
      android:layout_height="match_parent" />

</LinearLayout>

您给xml提供了错误的包名引用。根据错误,您的包名为

com.chiari.nicola.myapplication
因此,在xml中,您给出了
com.example.android.fragments
。您需要将其设置为包名。您的
large.xml
应该如下所示

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment android:name="com.chiari.nicola.myapplication.HeadlinesFragment"
      android:id="@+id/headlines_fragment"
      android:layout_weight="1"
      android:layout_width="0dp"
      android:layout_height="match_parent" />

   <fragment android:name="com.chiari.nicola.myapplication.ArticleFragment"
      android:id="@+id/article_fragment"
      android:layout_weight="2"
      android:layout_width="0dp"
      android:layout_height="match_parent" />

</LinearLayout>


二进制XML文件行#23:错误膨胀类片段
首先在下面显示xmlcheck答案。我现在发现了我的错误!我在大型xml文件中更改了pacchetto的名称。。。。但是这个应用程序崩溃了。。。对于另一个错误…java.lang.IllegalArgumentException:DrumerLayout必须使用MeasureSpec.Exact进行测量。
com.chiari.nicola.myapplication
<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<fragment android:name="com.chiari.nicola.myapplication.HeadlinesFragment"
      android:id="@+id/headlines_fragment"
      android:layout_weight="1"
      android:layout_width="0dp"
      android:layout_height="match_parent" />

   <fragment android:name="com.chiari.nicola.myapplication.ArticleFragment"
      android:id="@+id/article_fragment"
      android:layout_weight="2"
      android:layout_width="0dp"
      android:layout_height="match_parent" />

</LinearLayout>