Search code examples
javaandroidandroid-xmlclassnotfoundexceptionandroid-inflate

Why does an InflateException (Caused by ClassNotFoundException) occur?


I am developing a metronome app. I am doing the part where I let people to select the tempo. And looks something like this:

    Tempo:    <-- TextView
      90      <-- EditText
  --O------   <-- SeekBar

But then I changed my mind and changed the EditText to TextView. This is part of the xml:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center_horizontal">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="@dimen/all_text_size"
        android:text="@string/tempo_text"/>
    <TexView //This used to be an EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tempo_text"/>
    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="270"
        android:id="@+id/tempo_seek"/>
</LinearLayout>

Before the change, it works fine. But after the change, the tempo_text TextView has a warning that says:

Element TextView is not allowed here

I am confused, if the TextView above it, is allowed, why isn't it allowed? So I ignored the warning and thought it was just one of the bugs of Android Studio. When I run the app, an exception occurred:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.metronomewithvoice/com.themetronome.MainActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class TexView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2266)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
        at android.app.ActivityThread.access$600(ActivityThread.java:150)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:213)
        at android.app.ActivityThread.main(ActivityThread.java:5225)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class TexView
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
        at android.app.Activity.setContentView(Activity.java:1895)
        at com.themetronome.MainActivity.onCreate(MainActivity.java:15)
        at android.app.Activity.performCreate(Activity.java:5133)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
            at android.app.ActivityThread.access$600(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:5225)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
            at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.TexView" on path: DexPathList[[zip file "/data/app/com.metronomewithvoice-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.metronomewithvoice-2, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
        at android.view.LayoutInflater.createView(LayoutInflater.java:559)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
        at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:274)
            at android.app.Activity.setContentView(Activity.java:1895)
            at com.themetronome.MainActivity.onCreate(MainActivity.java:15)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
            at android.app.ActivityThread.access$600(ActivityThread.java:150)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:213)
            at android.app.ActivityThread.main(ActivityThread.java:5225)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
            at dalvik.system.NativeStart.main(Native Method)

And I'm sure that there is no problem with my Java code because the exception occurred on the setContentView line (MainActivity.java line 15).

Please tell me why does this exception occur, and how to fix it.


Solution

  • You have a typo TexView should be TextView