Pages

Tuesday, June 24, 2014

[Android] Error inflating class fragment


We have a project that will contain several fragments in one activity, we compile and deploy it to a device without any error message.  However, runtime exception occurs when we launch the App, even though we just declare a fragment and not use it yet.



At the first glance, I would consider that it is caused by the fragment class.  But it is actually caused by the XML syntax while declaring the fragment component in the layout file of my main activity.  See the rectangular area

android.view.InflateException: Binary XML file line #25: Error inflating class fragment

What happened?




It is due to the line 27 in the editor, which uses capital characters (even though it is exactly the same with the real java file we are going to use).  All I need to do it change them with all lower characters (it is legal to use capital ones in the rear).  That is to say, we revise it as

android:name="com.example.soundclassifier2.MusicFragment"

And everything works now!

No comments:

Post a Comment