引起:android.view.InflateException:二进制XML文件行#81:错误膨胀类片段android studio

时间:2015-02-12 17:59:10

标签: android xml tabs binary



<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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.riara.university.SchoolsTab$PlaceholderFragment">





</RelativeLayout>
&#13;
&#13;
&#13;

&#13;
&#13;
package com.riara.university;

import com.riara.university.TabPagerAdapter;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.Menu;

public class SchoolsTab extends FragmentActivity implements
        ActionBar.TabListener {

    private ViewPager viewPager;
    private TabPagerAdapter mAdapter;
    private ActionBar actionBar;
    // Tab titles
    private String[] tabs = { "Top Rated", "Games", "Movies" };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initilization
        viewPager = (ViewPager) findViewById(R.id.pager);
        actionBar = getActionBar();
        mAdapter = new TabPagerAdapter(getSupportFragmentManager());

        viewPager.setAdapter(mAdapter);
        actionBar.setHomeButtonEnabled(false);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        // Adding Tabs
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(this));
        }

        /**
         * on swiping the viewpager make respective tab selected
         * */
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                // on changing the page
                // make respected tab selected
                actionBar.setSelectedNavigationItem(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // on tab selected
        // show respected fragment view
        viewPager.setCurrentItem(tab.getPosition());
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    }

}
&#13;
&#13;
&#13;

&#13;
&#13;
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/pager"
    android:layout_width="match_parent" android:layout_height="match_parent"
    tools:context="com.riara.university.SchoolsTab" />
&#13;
&#13;
&#13;

尝试制作Tab视图并获取此

  

引起:android.view.InflateException:二进制XML文件行#81:错误膨胀类片段

&#13;
&#13;
02 - 12 20: 52: 49.867 2560 - 2560 / com.riara.university E / AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.riara.university, PID: 2560
java.lang.RuntimeException: Unable to start activity ComponentInfo {
  com.riara.university / com.riara.university.SchoolsTab
}: android.view.InflateException: Binary XML file line #81: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: android.view.InflateException: Binary XML file line # 81: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java: 763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java: 806)
at android.view.LayoutInflater.inflate(LayoutInflater.java: 504)
at android.view.LayoutInflater.inflate(LayoutInflater.java: 414)
at android.view.LayoutInflater.inflate(LayoutInflater.java: 365)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java: 377)
at android.app.Activity.setContentView(Activity.java: 2144)
at com.riara.university.SchoolsTab.onCreate(SchoolsTab.java: 25)
at android.app.Activity.performCreate(Activity.java: 5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2251)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2360)             at android.app.ActivityThread.access$800(ActivityThread.java: 144)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1278)             at android.os.Handler.dispatchMessage(Handler.java: 102)             at android.os.Looper.loop(Looper.java: 135)             at android.app.ActivityThread.main(ActivityThread.java: 5221)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java: 372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 899)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 694)
Caused by: java.lang.ClassCastException: Activity must implement NavigationDrawerCallbacks.
at com.riara.university.NavigationDrawerFragment.onAttach(NavigationDrawerFragment.java: 212)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java: 903)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java: 1104)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java: 1206)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java: 2159)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java: 297)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java: 727)             at android.view.LayoutInflater.rInflate(LayoutInflater.java: 806)             at android.view.LayoutInflater.inflate(LayoutInflater.java: 504)             at android.view.LayoutInflater.inflate(LayoutInflater.java: 414)             at android.view.LayoutInflater.inflate(LayoutInflater.java: 365)             at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java: 377)             at android.app.Activity.setContentView(Activity.java: 2144)             at com.riara.university.SchoolsTab.onCreate(SchoolsTab.java: 25)             at android.app.Activity.performCreate(Activity.java: 5933)             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1105)             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java: 2251)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java: 2360)             at android.app.ActivityThread.access$800(ActivityThread.java: 144)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java: 1278)             at android.os.Handler.dispatchMessage(Handler.java: 102)             at android.os.Looper.loop(Looper.java: 135)             at android.app.ActivityThread.main(ActivityThread.java: 5221)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java: 372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 899)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 694)
&#13;
&#13;
&#13;

以上是完整的错误,请您告诉我应该发布哪个文件

0 个答案:

没有答案