我正在尝试将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)当我运行这个应用程序时,它会崩溃:
无法启动活动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.mopub.mobileads.mopubview引起 在com.example.hroshandel.myapplication.SimpleIntro_FragmentActivity.onCreate(SimpleIntro_FragmentActivity.java:20) 原因: java.lang.ClassNotFoundException:没有在路径上找到类"com.mopub.mobileads.mopubview“:DexPathList[zip文件DexPathList/供应商/lib,/system/lib]
发布于 2015-05-26 15:08:27
请检查类名的错误,这是一个天才在文档中写道:
<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>但正确的类名是:
<com.mopub.mobileads.MoPubView> ... </com.mopub.mobileads.MoPubView>发布于 2014-12-29 04:27:55
就像上面的答案中提到的那样,你必须修复你的梯度。但除此之外,我还有同样的错误信息,运行这个应用程序,下面是我如何绕过它的方法:
<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
android:id="@+id/adContainer"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="50dp">
</FrameLayout> @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");
}
});发布于 2014-12-06 18:55:44
明显的问题是,您遵循了安装过程https://dev.twitter.com/mopub/android/getting-started吗?
编辑:
有格拉德尔
复制到您的项目中
$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') }https://stackoverflow.com/questions/27330635
复制相似问题