Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在xml布局中包含类时,Eclipse viewer无法实例化com.mopub.mobileads.MoPubView_Android_Eclipse_Mopub - Fatal编程技术网

Android 在xml布局中包含类时,Eclipse viewer无法实例化com.mopub.mobileads.MoPubView

Android 在xml布局中包含类时,Eclipse viewer无法实例化com.mopub.mobileads.MoPubView,android,eclipse,mopub,Android,Eclipse,Mopub,我能够下载并导入android的moPub库。遵循moPub站点上的简单示例后,应用程序在模拟器中运行良好。但是,添加控件后,eclipse viewer无法正确显示屏幕 xml包括[基于示例] <com.mopub.mobileads.MoPubView android:id="@+id/adview" android:layout_width="fill_parent" android:layout_height="50px" /

我能够下载并导入android的moPub库。遵循moPub站点上的简单示例后,应用程序在模拟器中运行良好。但是,添加控件后,eclipse viewer无法正确显示屏幕

xml包括[基于示例]

    <com.mopub.mobileads.MoPubView
        android:id="@+id/adview"
        android:layout_width="fill_parent"
        android:layout_height="50px" />

虽然这更像是一种刺激,而不是一种阻碍,但我宁愿让它发挥作用。提前非常感谢。

要获得快速修复,请在MoPub SDK项目中自己编辑MoPubView(假设您以这种方式添加了源代码,并与项目的其余部分一起编译),如果是这样,请在构造函数中的super调用之后添加以下行,该调用采用上下文和属性集参数:

    if (isInEditMode()) return;
下面是一个较大的代码段,显示了上述行的位置:

public MoPubView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (isInEditMode()) return;

    mContext = context;
    //[...the rest of the constructor's code...]
}
添加这一行(风格与品味)导致异常不会被抛出并在我的设备上运行,并且能够在测试中拉下一个320x50横幅广告(到目前为止,我还没有收到一个提供给模拟器的广告)

我对github进行了更改,并提出了拉取请求。 发布:版本1.14.1.0

Android SDK对isInEditMode()使用的整体理解:

我继续进行回购,然后
public MoPubView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (isInEditMode()) return;

    mContext = context;
    //[...the rest of the constructor's code...]
}