Error inflating class fragment

后端 未结 30 2192
长发绾君心
长发绾君心 2020-11-22 14:38

I get the Error

Unable to start activity ComponentInfo{de.androidbuch.activiti/de.androidbuch.activiti.task.Activity}: android.view.InflateException: Binar         


        
相关标签:
30条回答
  • 2020-11-22 14:55

    I got the same error, but my issue was that my fragment did not have an id in the xml layout of the parent activity.

    0 讨论(0)
  • 2020-11-22 14:56

    If you don't want to change anything and go with "fragment" tag

    do this,

    <fragment
     android:visibility="gone" (Visibility will not work, just helps in removing frag from xml viewer)(If you want the visibility to be gone make it in your fragment root element visibility=gone)
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:name="com.example.YOUR_FRAGMENT" (This is important)
     />
    
    0 讨论(0)
  • 2020-11-22 14:57

    Fragments cannot be nested in XML

    Learnt this the hard way - if you nest an XML layout based <fragment> tag inside a (potentially) dynamically loaded fragment from FragmentManager, then you start to get weird errors, trying to inflate your fragment xml.

    Turns out, that this is not supported - it will work fine if you do this through purely the FragmentManager approach.

    I was getting this problem because I was trying load a fragment inside a <DrawerLayout> from xml, and this was causing a crash in the onCreateView() method when I popped the back stack.

    0 讨论(0)
  • 2020-11-22 14:58

    I had the same problem. The solution for me was the order of super.onCreate and setContentView within the FragmentActivity

    Following order works fine:

        super.onCreate(savedInstanceState);
        setContentView(R.layout.fc_activity_list_profiles);
    
    0 讨论(0)
  • 2020-11-22 14:59

    For me it was after scrolling in the stack trace i found im missing the permission for android.permission.ACCESS_NETWORK_STATE

    after adding this permission it was fixed

    0 讨论(0)
  • 2020-11-22 15:02

    My problem in this case was a simple instance of having a dumb null pointer exception in one of my methods that was being invoked later in the lifecycle. This was causing the "Error inflating class fragment" exception for me. In short, please remember to check the further down the exception stack trace for a possible cause.

    Once I resolved the null pointer exception, my fragment loaded fine.

    0 讨论(0)
提交回复
热议问题