问题描述
当我在布局Android Studio布局预览中创建TextClock小部件时,提示并没有显示更改。但是在调试时,devise小部件可以完美运行。如果我评论了它,则布局预览工作成功。另一个PC Android Studio成功运行并显示TextClock。
When i created TextClock widget in layout Android Studio layout preview cahsed and didn't show the changes. But on debug devise widget work perfectly. If I commented it layout preview work successfuly. Another PC Android Studio work successfuly and show TextClock.
错误布局预览
java.lang.NullPointerException
at android.content.ContentResolver.registerContentObserver(ContentResolver.java:2263)
at android.widget.TextClock.registerObserver(TextClock.java:626)
at android.widget.TextClock.onAttachedToWindow(TextClock.java:545)
at android.view.View.dispatchAttachedToWindow(View.java:19575)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3437)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:44)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:355)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:404)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:657)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$7(RenderTask.java:788)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
TextClock XML代码
TextClock XML code
<TextClock
android:layout_width="120dp"
android:layout_height="35dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="16dp"
android:format24Hour="dd.MMMyyyy, HH:mm"
android:format12Hour="dd.MMM.yyyy, hh:mm a"
android:textColor="#d0ffffff"
android:textSize="30sp" />
将 minSdkVersion
更改为17并创建布局v17没有给出任何结果。
在Android Studio 3.6、3.6.1和4.0中发现的问题
Changing minSdkVersion
to 17 and creating layout v17 didn't give any results.Problem found in Android Studio 3.6, 3.6.1 and 4.0
推荐答案
注释您的TextClock并刷新预览,以及然后取消注释您的TextClock。
这将解决您的问题。
Comment your TextClock and refresh your preview, and then uncomment your TextClock.This will fix your issue.
升级到AS 3.6.1时遇到了此问题
I encountered this problem when I upgraded to AS 3.6.1
这篇关于布局预览中的TextClock渲染问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!