[Solved-4 Solutions] Error inflating class fragment
Error Description:
We get the Error
Unable to start activity ComponentInfo{de.androidbuch.activiti/de.androidbuch.activiti.task.Activity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
- when we switch via the portrait and the landscape mode and when we use fragments. The xml is:
- If we switch via landscape and portrait mode everything works fine. But when we click on the fragment and then switch to the other mode we get the error.
Solution 1:
- Make sure to use:
- And also make sure that the Activity that is using the fragment(s) extends FragmentActivity instead of the regular Activity to get the FragmentActivity class.
Solution 2:
- The exception android.view.InflateException: Binary XML file line: #... Error inflating class fragment might happen if you manipulate with getActivity() inside your fragment before onActivityCreated() get called. In such case you receive a wrong activity reference and can't rely on that.
- For instance the next pattern is wrong:
Pattern #1
Solution 3:
- Make sure your Activity extends FragmentActivity.
Solution 4:
- The solution for is the order of super.onCreate and setContentView within the FragmentActivity