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

时间:2017-01-13 16:19:58

标签: android

我想在mainActivity中使用灵活的ui。当我在模拟器日志上运行应用程序时显示错误:

  

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

mainActivity

public class ParentSpaceMainActivity extends AppCompatActivity
    implements NavigationView.OnNavigationItemSelectedListener, GoogleApiClient.OnConnectionFailedListener,ChildHomeworkList.Callbacks, ChildHomeworkAdd.Callbacks , ChildHomeworkUpdate.Callbacks {

private  ChildHomeworkList mChildHomeworkList = new ChildHomeworkList();
private  ChildHomeworkAdd mChildHomeworkAdd = new ChildHomeworkAdd();



//Constants
private static final String TAG = ParentSpaceMainActivity.class.getSimpleName();
private static final int RC_SIGN_IN = 9001;
// We instantiate just one time fragments during the life of the activity.




FragmentManager fm  = getSupportFragmentManager();
FragmentTransaction ft; // = fm.beginTransaction();
Fragment mFragment = null;
Fragment mHomeworkList=null;
Fragment mFragmentListChild = null;
Fragment mFragmentChat = null;
Fragment mFragmentMyAccount = null;
Fragment mFragmentMyFamily = null;

private DatabaseReference mRef;
private FirebaseAuth mFirebaseAuth;
private FirebaseUser mFirebaseUser;
private DatabaseReference mFirebaseDatabaseReference;
private OnDisconnect onDisconnectRef;
private FirebaseAuth.AuthStateListener mAuthListener;
private GoogleApiClient mGoogleApiClient;
private static int alreadyLog = 0;

private TextView nomNavHeader;

public String playMsgId;
private Button home;

private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000;
private BroadcastReceiver mRegistrationBroadcastReceiver;

private boolean isMobile = false;

@BindView(R.id.backgroundView1)
ImageView mBack1;

@BindView(R.id.backgroundView2)
ImageView mBack2;

private ValueAnimator animator;
private float mProgressValue;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(getResources().getBoolean(R.bool.portrait_only)){
        isMobile = true;
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    else
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    setContentView(R.layout.parents_main_space);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ButterKnife.bind(this);
    //FirebaseCrash.report(new Exception("My first Android non-fatal error"));

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();

    //po
    SharedPreferenceHelper sharedPreferenceHelper1 = new SharedPreferenceHelper(getApplicationContext());
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View navHeaderView = navigationView.inflateHeaderView(R.layout.nav_header_main);
    nomNavHeader = (TextView) navHeaderView.findViewById(R.id.UserName_nav_header);
    nomNavHeader.setText(sharedPreferenceHelper1.getSharedPreference().getString(KEY.FIRST_NAME,"DEFAULT"));

}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {

    int id = item.getItemId();

        mFragment = null;

     if (id == R.id.nav_manage) {
         getSupportActionBar().setTitle("Edukily");
         mFragment = mFragmentChat;
         fm.beginTransaction()
                 .remove(mFragmentListChild).commit();



    } else if (id == R.id.nav_gallery) {
         fm.beginTransaction()
                 .remove(mFragmentChat).commit();
         if (mFragmentListChild == null)
             setupFragmentListChild();

        mFragment=mFragmentListChild;


     } else if (id == R.id.nav_slideshow) {
        ParentSpaceListChild l =new ParentSpaceListChild();
         fm.beginTransaction().replace(R.id.drawer_layout,l ).commit();
    } else  if (id == R.id.nav_camera) {
         // Handle the camera action
         resetIfLogin();




    } else if (id == R.id.nav_share) {
        if (mFragmentMyAccount == null)
            setupFragmentMyAccount();

        getSupportActionBar().setTitle(R.string.my_account);
        mFragment = mFragmentMyAccount;


    } else if (id == R.id.nav_send) {
        if (mFragmentMyFamily == null)
            setupFragmentMyFamily();
        getSupportActionBar().setTitle(R.string.my_family);
        mFragment = mFragmentMyFamily;
    }

    if (mFragment != null) {
        fm.beginTransaction()
                .replace(R.id.root_frame_parents, mFragment).commit();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);

    return false;
}
}

mainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">

<include
    layout="@layout/app_bar_main"
    android:layout_width="match_parent"
    android:background="#FFFFFF"
    android:layout_height="match_parent" />


<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:background="#FFFFFF"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:menu="@menu/activity_main_drawer" />

<fragment
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:name="com.edukily.fragments.parents.ParentSpaceListChild"
    android:id="@+id/names_fragment"
    android:layout_weight="1"
    tools:layout="@layout/fragment_parents_list_child" />


    </android.support.v4.widget.DrawerLayout>

logcut

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.edukily, PID: 8747
              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.edukily/com.edukily.activities.ParentSpace.ParentSpaceMainActivity}: android.view.InflateException: Binary XML file line #50: Binary XML file line #50: Error inflating class fragment
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                  at android.app.ActivityThread.-wrap11(ActivityThread.java)
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                  at android.os.Handler.dispatchMessage(Handler.java:102)
                  at android.os.Looper.loop(Looper.java:148)
                  at android.app.ActivityThread.main(ActivityThread.java:5417)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
               Caused by: android.view.InflateException: Binary XML file line #50: Binary XML file line #50: Error inflating class fragment
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                  at com.edukily.activities.ParentSpace.ParentSpaceMainActivity.onCreate(ParentSpaceMainActivity.java:164)
                  at android.app.Activity.performCreate(Activity.java:6237)
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
               Caused by: android.view.InflateException: Binary XML file line #50: Error inflating class fragment
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                  at com.edukily.activities.ParentSpace.ParentSpaceMainActivity.onCreate(ParentSpaceMainActivity.java:164) 
                  at android.app.Activity.performCreate(Activity.java:6237) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
               Caused by: java.lang.IllegalStateException: Required view 'backgroundView1' with ID 2131689740 for field 'mBack1' was not found. If this view is optional add '@Nullable' (fields) or '@Optional' (methods) annotation.
                  at butterknife.internal.Finder.findRequiredView(Finder.java:62)
                  at butterknife.internal.Finder.findRequiredViewAsType(Finder.java:74)
                  at com.edukily.activities.ParentSpace.ParentSpaceMainActivity_ViewBinding.<init>(ParentSpaceMainActivity_ViewBinding.java:18)
                  at com.edukily.activities.ParentSpace.ParentSpaceMainActivity_ViewBinder.bind(ParentSpaceMainActivity_ViewBinder.java:13)
                  at com.edukily.activities.ParentSpace.ParentSpaceMainActivity_ViewBinder.bind(ParentSpaceMainActivity_ViewBinder.java:10)
                  at butterknife.ButterKnife.bind(ButterKnife.java:125)
                  at com.edukily.fragments.parents.ParentSpaceListChild.onCreateView(ParentSpaceListChild.java:160)
                  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1065)
                  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1268)
                  at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1370)
                  at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2415)
                  at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
                  at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:376)
                  at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
                  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:754)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284) 
                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
                  at com.edukily.activities.ParentSpace.ParentSpaceMainActivity.onCreate(ParentSpaceMainActivity.java:164) 
                  at android.app.Activity.performCreate(Activity.java:6237) 
                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) 
                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                  at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5417) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

2 个答案:

答案 0 :(得分:0)

在xml布局中尝试:

<fragment
android:layout_width="0dp"
android:layout_height="match_parent"
class="com.edukily.fragments.parents.ParentSpaceListChild"
android:id="@+id/names_fragment"
android:layout_weight="1"
tools:layout="@layout/fragment_parents_list_child" />

答案 1 :(得分:0)

在android.support.design.widget.NavigationView中生成错误它不支持较旧的Android版本,因此应用程序因上述错误而崩溃。

项目中有2个drawable.xml文件生成。当你创建drawable

文件在drawable.xml(v.21)中,它不支持较旧的Android版本。

不要将可绘制的xml文件放在drawable.xml(v.21)中。

从此文件夹中删除所有xml文件并将其放入drawable.xml