Error inflating class错误

简介:

09-30 23:30:01.968: E/AndroidRuntime(14741): Caused by: java.lang.NoSuchMethodException: WaterBoxView(Context,AttributeSet)
09-30 23:30:01.968: E/AndroidRuntime(14741): at java.lang.Class.getMatchingConstructor(Class.java:643)
09-30 23:30:01.968: E/AndroidRuntime(14741): at java.lang.Class.getConstructor(Class.java:472)
09-30 23:30:01.968: E/AndroidRuntime(14741): at android.view.LayoutInflater.createView(LayoutInflater.java:480)
09-30 23:30:01.968: E/AndroidRuntime(14741): ... 29 more

 

重点在于最后一句。

.NoSuchMethodException: WaterBoxView(Context,AttributeSet)

也就是没有这个对应的方法(没有定义inflate需要的默认构造函数),下面我们就实现它。

复制代码
1     public WaterBoxView(Context context, AttributeSet attrs) {
2         super(context, attrs);
3              LayoutInflater inflater = (LayoutInflater) context
5                 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
6         inflater.inflate(R.layout.water_box, this);
7 
8     }
复制代码

这样就行了。

 参考Error inflating class错误

本文转自陈哈哈博客园博客,原文链接http://www.cnblogs.com/kissazi2/archive/2012/09/30/2709449.html如需转载请自行联系原作者

kissazi2
相关文章
|
7月前
|
前端开发
【前端异常】Module build failed: Error: ENOENT: no such file or directory, scandir ‘G:\OPWeb\public\node_m
【前端异常】Module build failed: Error: ENOENT: no such file or directory, scandir ‘G:\OPWeb\public\node_m
73 0
|
6月前
|
Python
ERROR: file or directory not found: xx.py
​ 1、问题出现原因 在vscode中已导入pytest框架,做自动化demo小测试,运行Python文件一直出现如题错误,截图如下: ERROR: file or directory not found: xx.py  2、解决办法 1)直接把该文件移到当前主目录下,放在PYTHON-STUDY下 2)VSCode中右键tuopan.py文件,选择[在集成终端中打开],或者通过CD命令进入到tuopan.py文件所在目录 然后输入以下命令即可: 注:上述命令不是换行,在d:/前有空格 ,第一行信息为python所在安装路径,空格后的换行为运行的python文件的所在路径  
73 0
|
9月前
|
Java
成功解决:ERROR StatusLogger No log4j2 configuration file found.
成功解决:ERROR StatusLogger No log4j2 configuration file found.
|
9月前
|
Java
Java Error: The public type HelloWorld must be defined in its own file
Java Error: The public type HelloWorld must be defined in its own file
95 0
background引起错误:Error inflating class
background引起错误:Error inflating class
132 0
Dx unsupported class file version 52.0 Conversion to Dalvik format failed with error 1
Dx unsupported class file version 52.0 Conversion to Dalvik format failed with error 1
118 0
|
XML 数据格式
因为CircleImageView导致Binary XML file line #96: Error inflating class <unknown>
因为CircleImageView导致Binary XML file line #96: Error inflating class <unknown>
159 0
四十二、 ERROR org.apache.pig.Main - ERROR 2998: Unhandled internal error. Found class jline.Terminal
四十二、 ERROR org.apache.pig.Main - ERROR 2998: Unhandled internal error. Found class jline.Terminal
四十二、 ERROR org.apache.pig.Main - ERROR 2998: Unhandled internal error. Found class jline.Terminal
|
Java Spring
异常解决[ asm ClassReader failed to parse class file]
    异常解决[ asm  ClassReader failed to parse class file]   15:56:17,364 []-[DEBUG] Resolved location pattern [classpath*:com/baoy/**/*.
4273 0