A factory has already been set on this LayoutInflater
程序员文章站
2022-06-23 15:05:54
...
在重写Factory2的并给LayoutInflater设置的时候会遇到这个这个问题,通过源码可以发现问题所在:
可以发现当LayoutInflater中,当mFactorySet的值为true时会出现这个异常,因此只要把mFactorySet设置为false就不会有异常了,而mFactorySet又是private类型,只能通过反射来设置了:
设置好后运行,还是报相同的错:
A factory has already been set on this LayoutInflater
把鼠标放到getDeclaredField中的属性名mFactorySet上,出现提示:
这个属性不存在,可是源码中明明是存在,看看源码:
原来最大的支持SDK版本直到P(28)版本,
在build.gradle中修改targetSdkVersion为28:
可以发现程序运行正常了!
推荐阅读
-
tomcat6下jsp出现getOutputStream() has already been called for this response异常的原因和解决方法
-
Zuul Filter过滤器返回信息提示getWriter() has already been called for this response
-
解决java.lang.IllegalStateException: getWriter() has already been called for this response
-
java.lang.IllegalStateException: getOutputStream() has already been called for this response
-
getOutputStream() has already been called for this response解决方案
-
getOutputStream() has already been called for this response解决方案
-
getOutputStream() has already been called for this response
-
A factory has already been set on this LayoutInflater
-
The bean 'dataSource',could not be registered.A bean with that name has already been defined解决办法
-
tomcat6下jsp出现getOutputStream() has already been called for this response异常的原因和解决方法