Error inflating class fragment

后端 未结 30 2187
长发绾君心
长发绾君心 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:41

    If your TaskDetailsFragment extending android.app.Fragment, do change in onCreateView().

    Return your view which you want to show in the Fragment or convert your Layout to view by using LayoutInflater and return it.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View mainview = inflater.inflate(R.layout.main, null);
        return mainview;
    }
    

    Hope this works. :)

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

    I was receiving this error in android studio the problem was that my fragment had a relative layout while the code on the OnCreateView function was

    mDrawerListView = (ListView) inflater.inflate(
                    R.layout.fragment_navigation_drawer, container, false);
    

    is your code doing the same thing?

    0 讨论(0)
  • Could you post the fragment's onCreate and onCreateView methods? I had exactly same exception which was caused by an exception in the fragment onCreate method, when I fixed that problem it fixed the Error inflating class fragment.

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

    I had a similar problem; after running the AdMob example, I tried to insert Ads in my app, causing this error:

    01-02 16:48:51.269    8199-8199/it.dndc.BreathPlot E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.IllegalStateException: Could not execute method of the activity
     Caused by: android.view.InflateException: Binary XML file line #57: Error inflating class fragment
    

    The solution is: you cannot insert the fragment for an Ad into a ListActivity. Instead, I could add it to a FragmentActivity and to an ActionBarActivity without any problem.

    My suggestion is: start from the AdMob example and add into it your existing app: I would have saved a lot of time !!!

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

    If you use obfuscation with Navigation component you need to exclude android's fragment and your args. Add these lines to your proguard-rules files:

    # Exclude the fragments and argType for navigation component.
    -keep class * extends androidx.fragment.app.Fragment{}
    -keep class com.safetonet.presentation.features.parent.affffdevice.model.PresentableAddDeviceData
    
    0 讨论(0)
  • 2020-11-22 14:43

    I was receiving this error for different reasons.

    Steps to reproduce:

    ~> My issue was that I created a brand new blank application.

    ~> I then generated a custom fragment from the File ~> New File Menu.

    ~> Proceeded to customize the fragment by adding layouts and buttons etc.

    ~> Referenced the new custom fragment in the auto generated activity_my.xml that was generated for me when creating the application. Doing this allowed the XML to generate the objects for me.

    Heres is the catch when generating the custom fragment via File ~> New File Menu it auto generates an interface function stub and places it at the bottom of the fragment class file.

    This means that your MyActivity class must implement this interface. If it does not then the the above error occurs only when referencing the fragment from xml. By removing the reference for the Fragment in the XML completely, and creating the fragment through code in the MyActivity.java class file Logcat generates a more concise error explaining the issue in detail and complaining about the interface. This is demonstrated in the Project Template Activity+Fragment. Although, <~that Project Template does not generate the interface stub.

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