【问题标题】:Eclipse viewer unable to instantiate com.mopub.mobileads.MoPubView when including the class in an xml layout将类包含在 xml 布局中时,Eclipse 查看器无法实例化 com.mopub.mobileads.MoPubView
【发布时间】:2012-07-02 16:55:06
【问题描述】:

我能够下载并导入适用于 android 的 moPub 库。按照 moPub 网站上的简单示例进行操作后,该应用程序在模拟器中运行良好。但是添加控件后eclipse查看器无法正常显示屏幕。

xml包含[基于示例]

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

当我尝试转到“图形布局”选项卡时导致以下错误

The following classes could not be instantiated:
- com.mopub.mobileads.MoPubView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse

虽然这更像是一种刺激而不是炫耀,但这是我宁愿做的事情。非常感谢您。

【问题讨论】:

    标签: android eclipse mopub


    【解决方案1】:

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

        if (isInEditMode()) return;
    

    这是一个更大的 sn-p 显示上述行的位置:

    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 https://github.com/mopub/mopub-android-sdk

    Android SDK 对整个 isInEditMode() 用法的看法: http://developer.android.com/reference/android/view/View.html#isInEditMode()

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    相关资源
    最近更新 更多