首页 文章

我的FragmentActivity中的ClassNotFoundException mopub

提问于
浏览
2

我正在尝试将mopub添加到我的应用中 . 我通过AndroidStudio插件安装了sdk . 并将此添加到我的xml中

<com.mopub.mobileads.mopubview
   android:id="@+id/adview"
    android:layout_alignParentBottom="true"
    android:layout_width="fill_parent"
    android:layout_height="50dp">
</com.mopub.mobileads.mopubview>

但它给了我这些错误:

The following classes could not be found:
- com.mopub.mobileads.mopubview (Fix Build Path, Create Class)

当我运行应用程序时崩溃:

java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.hroshandel.myapplication / com.example.hroshandel.myapplication.SimpleIntro_FragmentActivity}:android.view.InflateException:二进制XML文件行#15:错误输出类com . mopub.mobileads.mopubview引起:android.view.InflateException:二进制XML文件行#15:在com.example.hroshandel.myapplication.SimpleIntro_FragmentActivity.onCreate(SimpleIntro_FragmentActivity.java:20)中输入类com.mopub.mobileads.mopubview时出错引起:java.lang.ClassNotFoundException:在路径上找不到类“com.mopub.mobileads.mopubview”:DexPathList [[zip file“/data/app/com.example.hroshandel.myapplication-4.apk”] ,nativeLibraryDirectories = [/ data / app-lib / com.example.hroshandel.myapplication-4,/ vendor / lib,/ system / lib]]

3 回答

  • 8

    请检查 class 名称的错字,在文档中写一个天才:

    <com.mopub.mobileads.mopubview
       android:id="@+id/adview"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="50dp">
    </com.mopub.mobileads.mopubview>
    

    但正确的 class 名称是:

    <com.mopub.mobileads.MoPubView> ... </com.mopub.mobileads.MoPubView>
    
  • 0

    好像你必须如上面的答案中所述修复你的gradle . 但除此之外,我有相同的错误消息运行应用程序,这是我如何能够解决它:

    • 删除MoPub广告视图的设计时参考 .
    <com.mopub.mobileads.mopubview
           android:id="@+id/adview"
            android:layout_alignParentBottom="true"
            android:layout_width="fill_parent"
            android:layout_height="50dp">
        </com.mopub.mobileads.mopubview>
    
    • 而是放一个容器 . 我选择使用FrameLayout:
    <FrameLayout
        android:id="@+id/adContainer"
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_height="50dp">
        </FrameLayout>
    
    • 在Activity中,我通过实例化,分配和加载我的广告,然后使用BannerAdListener onBannerLoaded事件将其添加到adContainer来以编程方式加载MoPubView:
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Fabric.with(this, new Crashlytics()); // optional library
            setContentView(R.layout.main_activity);
            ButterKnife.inject(this); // optional, used to inject views e.g. adContainer
    
            MoPubView moPubView = new MoPubView(this);
    
            moPubView.setAdUnitId("ad unit id");
            moPubView.loadAd();
            moPubView.setBannerAdListener(new MoPubView.BannerAdListener() {
                @Override
                public void onBannerLoaded(MoPubView moPubView) {
                    Log.d(TAG, "Banner loaded");
                    try {
                        mAdContainer.addView(moPubView);
                    }
                    catch(Exception ex){
                        Log.d(TAG, "Error loading banner add to container");
                    }
                }
    
                @Override
                public void onBannerFailed(MoPubView moPubView, MoPubErrorCode moPubErrorCode) {
                    Log.d(TAG, "Banner failed");
                }
    
                @Override
                public void onBannerClicked(MoPubView moPubView) {
                    Log.d(TAG, "Banner clicked");
                }
    
                @Override
                public void onBannerExpanded(MoPubView moPubView) {
                    Log.d(TAG, "Banner expanded");
                }
    
                @Override
                public void onBannerCollapsed(MoPubView moPubView) {
                    Log.d(TAG, "Banner collapsed");
                }
            });
    
  • 3

    您是否按照设置流程提出了明显的问题https://dev.twitter.com/mopub/android/getting-started

    编辑:

    有GRADLE

    复制到您的项目中

    $MY_PROJECT_DIR $ mkdir mopub-sdk
    $MY_PROJECT_DIR $ cp -R $MOPUB_DIR/mopub-android-sdk/mopub-sdk mopub-sdk
    

    添加到build.gradle

    include ':app', ':mopub-sdk'
    dependencies { compile project(':mopub-sdk') }
    

相关问题