根据此问题中提供的建议,我修改了我的AdMob代码以符合建议,这有效地减少了出现的异常数量.然而,一个新的例外正在上升.
代码如下:
@Override
protected void onDestroy() {
if ( adView != null ) {
adView.destroy();
adView = null;
Log.i(ApplicationData.APP_TAG, TAG + ": OnDestroy, destroying the Adview");
}
super.onDestroy();
}
Run Code Online (Sandbox Code Playgroud)
adView.destroy()
发布LogCat消息时,该方法似乎运行良好.在此消息之后,我收到以下异常WebView
:
java.lang.NullPointerException
at android.webkit.WebViewClassic.loadDataWithBaseURL(WebViewClassic.java:2741)
at android.webkit.WebView.loadDataWithBaseURL(WebView.java:919)
at com.google.android.gms.ads.internal.request.n.run(SourceFile:206)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我无法找到重现问题的方法,但是经常在生产中发生.我一直没能找到任何问题,有人暗示我能做些什么吗?
我希望所附的屏幕截图可以使我的问题更清楚:RecyclerView
列表中的最后一项正与重叠AdView
。
在的底部添加空白和边距RecyclerView
,在的底部底部留出空白AdView
,这是不可取的。
有什么方法可以设置过度滚动或偏移滚动吗?
任何快速的解决方案/建议将是有益的,在此先感谢。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v7.widget.RecyclerView
android:id="@+id/rvProverbs"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:spanCount="4"
/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/ad_unit_id">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试查看如何在UITabBarController下添加UIView,以便可以向我的应用添加广告,我似乎无法找出将UIView限制在选项卡栏底部的任何方法。这可能吗?
编辑:在选项卡栏的底部,我的意思是在选项卡栏的下方
我正在测试Adview
我的布局.如果我放置Adview
之前ListView
一切都很好,但如果我把它放在它之后ListView
它就不会出现.
怎么了?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:background="@android:color/white" />
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxx"
ads:testDevices="xxxx" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我正在尝试在Android中使用AdMob并遵循教程.我已成功下载,安装并添加了Google Play服务库.几乎一切似乎都很好.
然而,Eclipse固执地在"adView.setAdSize"位下给出了一个红色下划线.错误消息显示"AdView类型中的方法setAdSize(AdSize)不适用于参数(AdSize)".我没有看到什么是错的,该代码符合我能找到的所有教程和文档,以及为什么setAdSize(AdSize)不会将AdSize作为参数?这对我来说没有意义.
不幸的是,设置广告尺寸对于代码运行是必要的,因此我不能只删除该位.相关代码如下.感谢任何可以提供帮助的人.
...
import com.google.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends ActionBarActivity{
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Create the adView.
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("ID REMOVED FOR PRIVACY REASONS");
...
}
...
}
Run Code Online (Sandbox Code Playgroud) 我只是尝试在我的布局中加入Adview.工作正常,但如果没有Internet连接则显示空格.正如我到目前为止所读到的,我理解admob的标准行为是仅在显示广告时占用空间.否则,例如.没有互联网连接,它不应该占用任何布局空间.我列出了我认为我可能犯了错误的代码,这就是我遇到这种奇怪行为的原因......
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF"
android:weightSum="1">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<include layout="@layout/content_main"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后,在app gradle中:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-ads:9.2.0'
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
在模块gradle中:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'
Run Code Online (Sandbox Code Playgroud)
我想我做错了什么,所以请帮我一个建议.谢谢!