Resources$NotFoundException: Resource ID #0x0
插件里面自定义了一个CommonDialog,布局文件也在插件中。直接使用宿主的Context创建该CommonDialog时会报错,日志如下所示:
android.content.res.Resources$NotFoundException: Resource ID #0x0 at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:423) at android.content.res.Resources.loadXmlResourceParser(Resources.java:2398) at android.content.res.Resources.getLayout(Resources.java:1292) at android.view.LayoutInflater.inflate(LayoutInflater.java:534) at com.android.internal.policy.HwPhoneLayoutInflater.inflate(HwPhoneLayoutInflater.java:138) at com.xxx.xxxxxx.CommonDialog.init(CommonDialog.java:52)
CommonDialog报错位置的代码如下所示:
contentView = LayoutInflater.from(context).inflate(R.layout.layout_common_dialog,null,false);
请问有没有解决方法?感谢感谢!
LayoutInflater就是通过Context找到对应Resources的,要不Context怎么叫“上下文”呢?
如果不用xml自动inflate出view,建议直接让插件暴露createView的Java接口给宿主调用。