你的位置:首页 > 信息动态 > 新闻中心
信息动态
联系我们

Android stuido 解决Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file

2021/11/30 23:41:59

Android stuido 解决Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file

程序之美

在这里插入图片描述

今天在github上下载了一个工程导入到本地,编译,就报如下错误:

Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class

11-30 20:19:04.410 19868-19868/jerome.com.usbcamera E/AndroidRuntime: FATAL EXCEPTION: main
    Process: jerome.com.usbcamera, PID: 19868
    java.lang.RuntimeException: Unable to start activity ComponentInfo{jerome.com.usbcamera/jerome.com.usbcamera.MainActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class jerome.com.usbcamera.CameraView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5431)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class jerome.com.usbcamera.CameraView
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at jerome.com.usbcamera.MainActivity.onCreate(MainActivity.java:29)
        at android.app.Activity.performCreate(Activity.java:6251)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5431) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
     Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class jerome.com.usbcamera.CameraView
        at android.view.LayoutInflater.createView(LayoutInflater.java:645)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at jerome.com.usbcamera.MainActivity.onCreate(MainActivity.java:29) 
        at android.app.Activity.performCreate(Activity.java:6251) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5431) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at android.view.LayoutInflater.createView(LayoutInflater.java:619)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at jerome.com.usbcamera.MainActivity.onCreate(MainActivity.java:29) 
        at android.app.Activity.performCreate(Activity.java:6251) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5431) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
     Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/jerome.com.usbcamera-2/base.apk"],nativeLibraryDirectories=[/data/app/jerome.com.usbcamera-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libUsbCameraProc.so"
        at java.lang.Runtime.loadLibrary(Runtime.java:367)
        at java.lang.System.loadLibrary(System.java:1076)
        at jerome.com.usbcamera.ImageProc.<clinit>(ImageProc.java:41)
        at jerome.com.usbcamera.CameraView.<init>(CameraView.java:32)
        at java.lang.reflect.Constructor.newInstance(Native Method) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
        at jerome.com.usbcamera.MainActivity.onCreate(MainActivity.java:29) 
        at android.app.Activity.performCreate(Activity.java:6251) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5431) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

经过多方研究,发现引起上述问题的主要有如下原因:

  1. 引用类名问题:自定义了一个View,用于布局文件中,假设包名为com.example.cc,类名叫CameraView,这个时候在XML作为布局元素引用的话,必须使用完整路径名,也就是包名加类名来引用,用com.example.cc.CameraView来进行引用。

    2.构造函数问题:自定义一个View,必须派生实现基类View的三个构造函数

    CameraView(Context context) //Simple constructor to use when creating a view from code

    CameraView(Context context, AttributeSet attrs) //Constructor that is called when inflating a view from XML

    CameraView(Context context, AttributeSet attrs, int defStyle) //Perform inflation from XML and apply a class-specific base style

我的就是第二个问题引起的,增加如下构造函数问题解决。

	public CameraView(Context context) {
		super(context);
		initCameraView(context);
	}

	public CameraView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initCameraView(context);
	}
	public CameraView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);     //Perform inflation from XML and apply a class-specific base style
		initCameraView(context);

	}

就此记下,希望能够帮助到遇到和我同样的问题,仍然在迷茫中的小伙伴。你们的进步,是我最大的幸福。