gpt4 book ai didi

android-studio - 不要在预览窗口创建线程 - 华为广告实现

转载 作者:行者123 更新时间:2023-12-04 13:51:37 26 4
gpt4 key购买 nike

我正在android应用程序中实现华为广告。我已经完成了所有 https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides/publisher-service-banner-0000001050066915并成功实现了广告,但 android studio preview 给了我错误,并且在 xml 中添加华为广告时没有显示预览。删除后显示华为广告预览。
以下是我的布局:

 <?xml version="1.0" encoding="utf-8"?>
<com.huawei.hms.ads.nativead.NativeView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/native_video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#FFFFFF"
android:orientation="vertical">
<com.huawei.hms.ads.nativead.MediaView
android:id="@+id/ad_media"
android:layout_width="match_parent"
android:layout_height="@dimen/_200sdp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_50sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@color/white">
<TextView
android:id="@+id/ad_title"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:alpha="1"
android:textColor="#000000"
android:textSize="@dimen/hiad_text_13_sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="@+id/ad_source"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:layout_marginStart="24dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="16dp"
android:alpha="0.6"
android:text="asdfasj"
android:maxWidth="158dp"
android:textColor="#666666"
android:textSize="@dimen/hiad_text_12_sp"
app:layout_constraintStart_toStartOf="@id/ad_title"
app:layout_constraintEnd_toStartOf="@id/ad_flag"
app:layout_constraintTop_toBottomOf="@id/ad_title"
/>

<TextView
android:id="@+id/ad_flag"
android:layout_width="20dp"
android:layout_height="14dp"
android:background="@drawable/native_flag_rounded_corners_shape"
android:text="@string/ad_flag"
android:textColor="#FFFFFF"
android:textSize="8sp"
android:layout_marginStart="@dimen/_10sdp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@id/ad_source"
app:layout_constraintStart_toEndOf="@id/ad_source"
app:layout_constraintTop_toTopOf="@id/ad_source" />

<Button
android:id="@+id/ad_call_to_action"
android:layout_width="72dp"
android:layout_height="26dp"
android:layout_alignParentEnd="true"
android:background="@drawable/native_button_rounded_corners_shape"
android:textColor="#FFFFFF"
android:textSize="10sp"
android:layout_marginEnd="@dimen/_20sdp"
app:layout_constraintBottom_toBottomOf="@+id/ad_source"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</com.huawei.hms.ads.nativead.NativeView>
以下是我遇到的错误
enter image description here
当我将根标记删除到约束布局时。预览在屏幕上可见,所有错误都消失了。在这两个标签中,我面临以下异常:

FirstException: Don't Create Threads in Preview

java.lang.IllegalStateException: It is not allowed to create newthreads in the preview   at com.huawei.hms.ads.kn.newThread  atjava.util.concurrent.ThreadPoolExecutor$Worker.(ThreadPoolExecutor.java:623)  atjava.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:912)  atjava.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1343)  at com.huawei.hms.ads.km.Code  at com.huawei.hms.ads.km.I  atcom.huawei.hms.ads.lj.Code  at com.huawei.hms.ads.lj.V  atcom.huawei.hms.ads.dl.Z  at com.huawei.hms.ads.dl.V  atcom.huawei.hms.ads.dl.Code  atcom.huawei.openalliance.ad.views.PPSNativeView.Code  atcom.huawei.openalliance.ad.views.PPSNativeView.  atcom.huawei.hms.ads.nativead.NativeView.  atjdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-2)  atjdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)  atjdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  at java.lang.reflect.Constructor.newInstance(Constructor.java:490)  atandroid.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)  at android.view.LayoutInflater.inflate(LayoutInflater.java:657)   atandroid.view.LayoutInflater.inflate(LayoutInflater.java:499)


Second Exception: Failed to instantiate One Or more Class Thefollowing classes could not be instantiated:- com.huawei.hms.ads.nativead.MediaView (Open Class, Show Exception, Clear Cache)- com.huawei.openalliance.ad.views.VideoView (Open Class, Show Exception, Clear Cache) Tip: Use View.isInEditMode() in your customviews to skip code or show sample data when shown in the IDE. If thisis an unexpected error you can also try to build the project, thenmanually refresh the layout. Exception Detailsjava.lang.NullPointerException   atcom.huawei.openalliance.ad.views.NativeVideoView.Code  atcom.huawei.openalliance.ad.views.NativeVideoView.  atcom.huawei.hms.ads.nativead.MediaView.Code  atcom.huawei.hms.ads.nativead.MediaView.  atjdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(NativeConstructorAccessorImpl.java:-2)  atjdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)  atjdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  at java.lang.reflect.Constructor.newInstance(Constructor.java:490)  atandroid.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)  atandroid.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1121)  atandroid.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)  at android.view.LayoutInflater.rInflate(LayoutInflater.java:1095)  atandroid.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)  at android.view.LayoutInflater.inflate(LayoutInflater.java:680)   atandroid.view.LayoutInflater.inflate(LayoutInflater.java:499)


我已使缓存无效并重新启动 Android Studio,但还没有任何效果。任何人都可以帮我渲染预览。任何帮助,将不胜感激。谢谢

最佳答案

目前,Ads kit SDK 引用了 HMS 基础 SDK 代码,但您似乎尚未集成 HMS 基础 SDK。
结果,在预览期间出现以下错误。
enter image description here
如果您选择不集成 HMS 基础 SDK,则 Ads SDK 功能不受影响,但在预览时会受到影响。
所以有两个选项供您引用:
一种方法是你可以尝试集成hms基础sdk,或者另一种方法是忽略这个预览错误,因为这不会影响实际操作。

关于android-studio - 不要在预览窗口创建线程 - 华为广告实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68918794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com