【发布时间】:2014-12-10 11:50:02
【问题描述】:
这是我的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<com.mopub.mobileads.MoPubView
android:id="@+id/adview"
android:layout_width="fill_parent"
android:layout_height="50dp"
/>
</RelativeLayout>
我正在将 MoPub SDK 集成到我的 libGDX 游戏中,在 MoPub 文档中,他们说要在 layout.xml 中创建 MopubView,如上所示。然后,执行以下操作:
moPubView = (MoPubView) findViewById(R.id.adview);
moPubView.setAdUnitId("xxxxxxxxxxx"); // Enter your Ad Unit ID from www.mopub.com
moPubView.loadAd();
RelativeLayout layout = new RelativeLayout(this);
// Create the libgdx View
View gameView = initializeForView(new TBGame(this), config);
// Add the libgdx view
layout.addView(gameView);
layout.addView(moPubView)
setContentView(layout);
但 libGDX 不会加载我的 xml 文件,因为它不需要它,每当执行到上述行时,就会导致空指针异常。所以解决方案似乎是从代码创建视图?我怎样才能做到这一点? Integrating Mopub ads into Cocos2dx 2.1 有一个非常相似的问题,但该解决方案声明对于最新的 MoPub SDK 无效。
编辑:这是 MoPubView 类https://github.com/mopub/mopub-android-sdk/blob/master/mopub-sdk/src/main/java/com/mopub/mobileads/MoPubView.java
附件:此处附加的堆栈跟踪的一部分:
【问题讨论】:
-
请发布您的 MoPubView 课程,我们甚至可以说任何内容,或者完整的异常堆栈。
-
我已经用 MoPubView 类的链接更新了帖子。请检查一下。我会尽快发布堆栈跟踪。
-
堆栈跟踪略有变化。请立即检查,因为这是带有原始代码的那个