我已经创建了一个多模块项目。我已经在它的一个库模块中使用数据绑定创建了一个自定义视图。
**问题:**自定义视图未显示在布局编辑器中,但在设备上显示正常。这是布局编辑器问题中显示的错误:
java.lang.ClassNotFoundException: androidx.databinding.DataBinderMapperImpl
at com.android.tools.idea.rendering.classloading.RenderClassLoader.getNonProjectClassData(RenderClassLoader.java:244)
at com.android.tools.idea.rendering.classloading.RenderClassLoader.loadClassFromNonProjectDependency(RenderClassLoader.java:207)
at org.jetbrains.android.uipreview.ModuleClassLoader.load(ModuleClassLoader.java:379)
at com.android.tools.idea.rendering.classloading.RenderClassLoader.findClass(RenderClassLoader.java:169)
at org.jetbrains.android.uipreview.ModuleClassLoader.findClass(ModuleClassLoader.java:332)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.jetbrains.android.uipreview.ModuleClassLoader.loadClass(ModuleClassLoader.java:287)
at ir.kharidarim.core.ui.custom.TitledEditText.init(TitledEditText.java:72)
at ir.kharidarim.core.ui.custom.TitledEditText.<init>(TitledEditText.java:63)
at jdk.internal.reflect.GeneratedConstructorAccessor3564.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.jetbrains.android.uipreview.ViewLoader.createNewInstance(ViewLoader.java:399)
at org.jetbrains.android.uipreview.ViewLoader.loadClass(ViewLoader.java:189)
at org.jetbrains.android.uipreview.ViewLoader.loadView(ViewLoader.java:147)
at com.android.tools.idea.rendering.LayoutlibCallbackImpl.loadView(LayoutlibCallbackImpl.java:303)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:417)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:428)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:332)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1121)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1124)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1124)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:499)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:353)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:431)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:714)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$7(RenderTask.java:870)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
我已经将dataBinding = true
添加到build.gradle
。我使用的是Android Studio Arctic Fox。Clean and rebuild
和Invalidate cache
都不起作用。
1条答案
按热度按时间bvhaajcl1#
通过在
build.gradle
中设置viewBinding = true
解决