Skip to content Skip to sidebar Skip to footer

Android - Error When Inflating Custom View In Xml

I have a custom view but I'm unable to use it because something related to namespaces that causing an Exception: E/AndroidRuntime: FATAL EXCEPTION: main Process:

Solution 1:

You need to use the fully-qualified name of your view. Use <com.example.pc.easycalc.MyDisplay> in your layout xml. When a fully qualified name is not specified, the LayoutInflater defaults to searching in android.widget and android.view, and your view does not exist in those packages.

Solution 2:

The problem is defined as:

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.MyDisplay"

you are declaring the view in your layout:

  <MyDisplay
        android:id="@+id/resDisplay"
        android:textSize="60sp"
        android:text="0.0000000"
        style="@style/DisplayStyle"
        />

but you have to set the complete package ( fully-qualified name ), i think that must be :

 <com.example.pc.easycalc.MyDisplay
        android:id="@+id/resDisplay"
        android:textSize="60sp"
        android:text="0.0000000"
        style="@style/DisplayStyle"
        />

Solution 3:

Call it using :

<com.example.pc.easycalc.MyDisplay
        android:id="@+id/resDisplay"
        android:textSize="60sp"
        android:text="0.0000000"
        style="@style/DisplayStyle"
        />

Solution 4:

It will give you an exception because except Google Library views no one can create a view that won't show the package name front of layout name:

So add the package name of your class front of layout name...


com. ___ .MyDisplay

Post a Comment for "Android - Error When Inflating Custom View In Xml"