简体   繁体   English

Eror在ConstrantLayout上添加了Facebook受众网络横幅

[英]Eror adding facebook audience network banner on ConstrantLayout

Hello there i have a problem adding a fan banner in my application i get a error i'v added the banner container in my layout 您好,我在应用程序中添加粉丝横幅时遇到问题我收到错误,我在布局中添加了横幅容器

<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.kimali.bhirod.MainActivity">

<LinearLayout
    android:id="@+id/banner_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    />

then i instantiate the Ad - View and load it in my activity 然后我实例化广告-查看并加载到我的活动中

public class MainActivity extends AppCompatActivity {

private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Instantiate an AdView view
    adView = new AdView(this, "153676755260608_153679028593714", AdSize.BANNER_HEIGHT_50);

    // Find the Ad Container
    LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);

    // Add the ad view to your activity layout
    adContainer.addView(adView);

    // Request an ad
    adView.loadAd(); setContentView(R.layout.activity_main);

but when i tried to test the code on my device i get this error saying 但是当我尝试在设备上测试代码时,出现此错误

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kimali.bhirod/com.kimali.bhirod.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.LinearLayout.addView(android.view.View)' on a null object reference

thanks 谢谢

You dont have setContentView(R.layout.your_layout) in your onCreate() . 您的onCreate()没有setContentView(R.layout.your_layout) onCreate() Without inflating the layout findViewById will return null. 在不扩大布局的情况下, findViewById将返回null。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Facebook受众网络导致NullPointerException - Facebook Audience Network cause NullPointerException 如何修复无法解析受众网络横幅上的“adView”方法 - How to fix cannot resolve method 'adView' on audience network banner 如何在 Facebook 受众网络插页式广告中设置点击计数器? - how to set click counter in facebook audience network interstitial ad? 加载本地广告时,Facebook Audience Network Ads应用程序崩溃 - Facebook Audience Network ads App crashes when Native ad is loading 需要使用Facebook Audience Network在文章列表中添加广告单元(NativeAd) - Need add Ad Unit (NativeAd) within a List of Articles, using Facebook Audience Network 用户点击后停止展示广告 15 秒 Facebook Audience Network - Stop showing ad for 15 seconds after user clicks on it Facebook Audience Network Facebook Audience Network Ad Sdk依赖项在Android App中显示运行时错误 - Facebook Audience Network Ad Sdk dependency giving run time error in Android App 为什么 Android Facebook Audience 网络在调用 destroy 方法后仍会泄漏活动? - Why Android Facebook Audience network is leaking activity even after calling destroy method? Google admob 和 Facebook 受众网络可以在不使用中介的情况下在同一应用上投放广告吗? - Can Google admob and Facebook audience network serve ads on the same app without using mediation? 在使用fb的Java sdk创建和添加用户后获取Facebook自定义受众洞察 - Fetching facebook custom audience insights after creating and adding users using fb's Java sdk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM