Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"android.view.InflateException: Binary XML file Error inflating class" error in WebView

My custom WebView class occurring error: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ates.aaa/com.example.ates.aaa.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class com.example.ates.aaa.MyWebView

MyWebView:

public class MyWebView extends WebView {

    public MyWebView(Context context) {
        super(context);
    }

}

MainActivity:

MyWebView wv;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    wv = (MyWebView) findViewById(R.id.myWebView);
    wv.loadUrl("www.google.com");

}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >


    <com.example.ates.aaa.MyWebView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/myWebView" />


</RelativeLayout>

full stacktrace:

04-06 11:50:46.267 8818-8818/com.example.ates.aaa D/dalvikvm: Late-enabling CheckJNI
04-06 11:50:46.283 8818-8818/com.example.ates.aaa W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
04-06 11:50:46.283 8818-8818/com.example.ates.aaa I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
04-06 11:50:46.283 8818-8818/com.example.ates.aaa W/dalvikvm: VFY: unable to resolve interface method 18801: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
04-06 11:50:46.283 8818-8818/com.example.ates.aaa D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
04-06 11:50:46.283 8818-8818/com.example.ates.aaa I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
04-06 11:50:46.283 8818-8818/com.example.ates.aaa W/dalvikvm: VFY: unable to resolve interface method 18805: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
04-06 11:50:46.283 8818-8818/com.example.ates.aaa D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
04-06 11:50:46.303 8818-8818/com.example.ates.aaa D/AndroidRuntime: Shutting down VM
04-06 11:50:46.303 8818-8818/com.example.ates.aaa W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa62f4288)
04-06 11:50:46.331 8818-8818/com.example.ates.aaa E/AndroidRuntime: 
    FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ates.aaa/com.example.ates.aaa.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class com.example.ates.aaa.MyWebView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
        at android.app.ActivityThread.access$600(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class com.example.ates.aaa.MyWebView
        at android.view.LayoutInflater.createView(LayoutInflater.java:596)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129)
        at com.example.ates.aaa.MainActivity.onCreate(MainActivity.java:20)
        at android.app.Activity.performCreate(Activity.java:5008)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
        at android.app.ActivityThread.access$600(ActivityThread.java:130) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:137) 
        at android.app.ActivityThread.main(ActivityThread.java:4745) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:511) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
        at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet]
        at java.lang.Class.getConstructorOrMethod(Class.java:460)
        at java.lang.Class.getConstructor(Class.java:431)
        at android.view.LayoutInflater.createView(LayoutInflater.java:561)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:267) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:129) 
        at com.example.ates.aaa.MainActivity.onCreate(MainActivity.java:20) 
        at android.app.Activity.performCreate(Activity.java:5008) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 
        at android.app.ActivityThread.access$600(ActivityThread.java:130) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        at android.os.Looper.loop(Looper.java:137) 
        at android.app.ActivityThread.main(ActivityThread.java:4745) 
        at java.lang.reflect.Method.invokeNative(Native Method) 
        at java.lang.reflect.Method.invoke(Method.java:511) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
        at dalvik.system.NativeStart.main(Native Method) 
04-06 11:50:46.351 8818-8821/com.example.ates.aaa D/dalvikvm: GC_CONCURRENT freed 229K, 3% free 10898K/11207K, paused 10ms+0ms, total 12ms
04-06 11:55:46.391 8818-8818/? I/Process: Sending signal. PID: 8818 SIG: 9
like image 217
ATES Avatar asked Apr 06 '16 18:04

ATES


1 Answers

Your com.example.ates.aaa.MyWebView class is missing a constructor that takes a Context and an AttributeSet as parameters. That constructor — such as this one on WebView — is required by all View subclasses that you wish to use in layout resources.

like image 182
CommonsWare Avatar answered Oct 18 '22 12:10

CommonsWare