Android:FATAL EXCEPTION:AdWorker#1 java.lang.NoSuchMethodError:java.io.IOException。<init> </init>

时间:2013-11-18 11:36:40

标签: android admob

几周以来,我收到了来自用户的以下崩溃报告

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>

我尝试了不同的横幅尺寸。没有帮助。删除广告请求代码可以解决问题,但也会删除广告。 有人知道吗?

2 个答案:

答案 0 :(得分:12)

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

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

  

注意:Google Play服务4.0。30(2013年11月发布)和更新版本   版本需要Android 2.3或更高版本。如果您的应用支持Android   2.2,您可以继续使用Google Play服务SDK进行开发,但必须从SDK安装Froyo的Google Play服务   管理器。

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

  

超过97%的设备现在运行Android 2.3(Gingerbread)或   更新的平台版本,我们正在放弃对Froyo的支持   发布Google Play服务SDK以使其成为可能   在未来提供更强大的API。这意味着你不会   能够在运行Android 2.2(Froyo)的设备上使用这些新API。

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

  

重要提示:因为很难预测每个设备的状态,   您必须先检查兼容的Google Play服务APK   您可以访问Google Play服务功能。对于许多应用程序,最好的时间   检查是在主活动的onResume()方法期间。

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

答案 1 :(得分:0)

我对此错误的体验似乎与Google Play服务不可用无关。 LogCat转储:

06-12 15:22:17.238:E / AndroidRuntime(5389):致命异乎寻常:AdWorker#1

06-12 15:22:17.238:E / AndroidRuntime(5389):java.lang.NoSuchMethodError:java.io.IOException。

06-12 15:22:17.238:E / AndroidRuntime(5389):at com.google.android.gms.internal.k.f(Unknown Source)

表示AdWorker中使用的方法丢失;虽然我没有得到任何屏幕截图,但我能够使用调试器逐步完成错误部分,看起来AdWorker正在使用String.isEmpty(),它只适用于API-9及之后;所以当我使用三星S1 API-8测试手机时,我崩溃了。