TextClock render problem in layout preview

岁酱吖の 提交于 2020-07-03 02:36:32

问题


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.

Error Layout preview

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 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" />

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


回答1:


Comment your TextClock and refresh your preview, and then uncomment your TextClock. This will fix your issue.

I encountered this problem when I upgraded to AS 3.6.1




回答2:


I had the same problem; my workaround was to convert the TextClock to a TextView via rightclick -> convert view as TextClock extends TextView, then the Layout renders, and after the Layout rendered I converted it back to a TextClock.

It's an ugly workaround - not a fix (you have to repeat it after closing Android Studio) - but at least I can see the layout now.

I will report it to Android Studio as a bug and hopefully they fix it



来源:https://stackoverflow.com/questions/60565227/textclock-render-problem-in-layout-preview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!