Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.

前端之家收集整理的这篇文章主要介绍了Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException.前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
几周以来,我收到了来自用户的以下崩溃报告
FATAL EXCEPTION: AdWorker #1
java.lang.NoSuchMethodError: java.io.IOException.<init>
at com.google.android.gms.internal.g.f(Unknown Source)
at com.google.android.gms.internal.g.b(Unknown Source)
at com.google.android.gms.internal.e.a(Unknown Source)
at com.google.android.gms.internal.e.a(Unknown Source)
at com.google.android.gms.internal.bq.ac(Unknown Source)
at com.google.android.gms.internal.cg$1.run(Unknown Source)
at com.google.android.gms.internal.ch$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)

除了它与谷歌广告/云服务有关,我不知道它来自哪里.直到昨天我才重现它,我启动了一个10英寸的模拟器并立即看到了问题.删除部分代码后,我认为以下部分是问题所在.

public void onActivityCreated(Bundle savedInstanceState) {

    ............

    AdView adView = (AdView)getActivity().findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
    .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
    .addTestDevice("CED2A4FD2C192C08557081CC37AA9E54")
    .build();
     adView.loadAd(adRequest);
}

奇怪的是它只发生在10英寸或更高的设备上.我测试了各种不同的设备/版本.该问题仅发生在10英寸设备或更大的设备上. Android版本并不重要. 2.2或4.4它不断崩溃.

根据我的理解,我没有针对特定设备尺寸的任何不同布局文件夹.
我的广告定义的xml如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/mainContainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/titleContainer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    </LinearLayout>

    <com.viewpagerindicator.TabPageIndicator
        android:id="@+id/indicator"
        style="@style/tabsbackground"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <LinearLayout
        android:id="@+id/adViewContainer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            ads:adUnitId="@string/adid"
            ads:adSize="SMART_BANNER"
            android:gravity="bottom"
            />
    </LinearLayout>

</LinearLayout>

我尝试了不同的横幅尺寸.没有帮助.删除广告请求代码可以解决问题,但也会删除广告.
谁有线索?

解决方法

Google移动广告现在通过Google Play Services 4.0提供,但由于Google Play服务不可用而出现此错误.很可能你会在Froyo遇到这个问题,那里有一个可以使用的特殊版本.

http://developer.android.com/google/play-services/setup.html

Note: Google Play services 4.0.30 (released November 2013) and newer
versions require Android 2.3 or higher. If your app supports Android
2.2,you can continue development with the Google Play services SDK,but must instead install Google Play services for Froyo from the SDK
Manager.

http:// android-developers.blogspot.no/2013/10/google-play-services-40.html

With over 97% of devices now running Android 2.3 (Gingerbread) or
newer platform versions,we’re dropping support for Froyo from this
release of the Google Play services SDK in order to make it possible
to offer more powerful APIs in the future. That means you will not be
able to utilize these new APIs on devices running Android 2.2 (Froyo).

https://developer.android.com/google/play-services/setup.html#ensure

Important: Because it is hard to anticipate the state of each device,
you must always check for a compatible Google Play services APK before
you access Google Play services features. For many apps,the best time
to check is during the onResume() method of the main activity.

Alernative 1用于在使用AdView之前检查Google Play服务是否可用.

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext();
if(status == ConnectionResult.SUCCESS) {
    //Success! Do what you want
}

Alernative 2是使用GoogleAdMobAdsSdk-6.4.1.jar

猜你在找的Android相关文章