android 渲染问题:调用目标异常

cnjp1d6j  于 2023-02-20  发布在  Android
关注(0)|答案(1)|浏览(140)

Problem occurs after updating my dependencies
These are the libraries I have added
This is my xml file.
Please solve this problem as I have tried it many times
java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at android.view.BridgeInflater.lambda$createViewFromCustomInflater$0(BridgeInflater.java:259) at android.view.BridgeInflater.createViewFromCustomInflater(BridgeInflater.java:285) at android.view.BridgeInflater.onCreateView(BridgeInflater.java:122) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:934) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:954) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1008) at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:309) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:965) at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1127) at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72) at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088) at android.view.LayoutInflater.inflate(LayoutInflater.java:686) at android.view.LayoutInflater.inflate(LayoutInflater.java:505) at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:360) at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:443) at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121) at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:722) at com.android.tools.idea.rendering.RenderTask.lambda$inflate$9(RenderTask.java:879) at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:194) at com.android.tools.idea.rendering.RenderExecutor$PriorityRunnable.run(RenderExecutor.kt:292) 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:829) Caused by: java.lang.NullPointerException at android.graphics.fonts.Font_Builder_Delegate.createBuffer(Font_Builder_Delegate.java:52) at android.graphics.fonts.Font$Builder.createBuffer(Font.java:264) at android.graphics.fonts.Font$Builder.(Font.java:200) at android.graphics.Typeface$Builder.(Typeface.java:517) at android.graphics.Typeface_Delegate.createFromDisk(Typeface_Delegate.java:91) at com.android.layoutlib.bridge.impl.ResourceHelper.getFont(ResourceHelper.java:495) at com.android.layoutlib.bridge.impl.ResourceHelper.getFont(ResourceHelper.java:507) at android.content.res.BridgeTypedArray.getFont(BridgeTypedArray.java:723) at android.widget.TextView.readTextAppearance(TextView.java:4154) at android.widget.TextView.(TextView.java:1165) at android.widget.TextView.(TextView.java:1066) at androidx.appcompat.widget.AppCompatTextView.(AppCompatTextView.java:113) at com.google.android.material.textview.MaterialTextView.(MaterialTextView.java:88) at com.google.android.material.textview.MaterialTextView.(MaterialTextView.java:83) at com.google.android.material.theme.MaterialComponentsViewInflater.createTextView(MaterialComponentsViewInflater.java:61) at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:148) ... 28 more

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    tools:context=".LoginActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="28dp"
        android:text="@string/chatter_box"
        android:textColor="#009688"
        android:textSize="28sp"
        android:textStyle="bold"

        />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="28dp"
        android:fontFamily=""
        android:text="@string/verify_your_number"
        android:textColor="@color/teal_200"
        android:textSize="28sp"
        android:textStyle="bold"/>

</LinearLayout>
cwtwac6a

cwtwac6a1#

您应该在TextView上指定一个fontFamily,否则预览时会崩溃。
例如,假设您希望使用Sans-Serif,则代码将如下所示:

<TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="28dp"
       android:fontFamily="sans-serif"
       android:text="@string/app_name"
       android:textColor="@color/teal_200"
       android:textSize="28sp"
       android:textStyle="bold"/>

相关问题