NoSuchMethodError com.google.android.gms.internal.g.f

时间:2013-11-19 20:28:18

标签: android google-play google-maps-android-api-2

我有一个难以解决的问题。我已经在Play上发布了我的应用程序,一切正常,但问题是有2台设备崩溃应用程序时出现以下错误:

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)

我只知道这个错误,因为Play告诉我,但是不可能看到它在哪里。此外,我有另一个信息。事情就是这样:当用户选择在抽屉菜单中查看地图并且错误是他第一次选择时,就会发生这种情况。

以下是此片段的代码:

package br.ufc.ondefica.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import br.ufc.ondefica.MainActivity;
import br.ufc.ondefica.R;
import br.ufc.ondefica.model.Placemark;
import br.ufc.ondefica.utils.DataHelper;
import br.ufc.ondefica.utils.ParserKML;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class UFCMapFragment extends FragmentWithSearch {
    private GoogleMap map;
    private int positionToShow = 3;
    private boolean isDefaultView = true;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.map_layout, container, false);
        ((MainActivity) getActivity()).setTitle(getResources().getStringArray(R.array.sliding_menu)[0]);
        return root;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        map = ((SupportMapFragment) getActivity().getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();
        map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
        map.setMyLocationEnabled(true);
        Bundle bundle = getArguments();
        if (bundle != null && bundle.containsKey("positionToShow")) {
            isDefaultView = false;
            positionToShow = bundle.getInt("positionToShow");
        }
        loadMap();
        // Move the camera instantly to the default place to show with a zoom of
        // 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(DataHelper.data.places
                .get(positionToShow).getCoordinates(), 13));
        // Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(16), 4000, null);
    }

    private void loadMap() {
        for (int i = 0; i < DataHelper.data.places.size(); i++) {
            Placemark place = DataHelper.data.places.get(i);
            Marker marker = map.addMarker(new MarkerOptions()
                    .icon(BitmapDescriptorFactory.fromResource(ParserKML
                            .loadMapOfIcons(place.getIconID())))
                    .title(place.getName()).snippet(place.getDescription())
                    .position(place.getCoordinates()));
            if (i == positionToShow && !isDefaultView)
                marker.showInfoWindow();
        }
    }

    public void onDestroyView() {
        super.onDestroyView();
        Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
        FragmentTransaction ft = getActivity().getSupportFragmentManager()
                .beginTransaction();
        ft.remove(fragment);
        ft.commit();
    }
}

崩溃的设备有:三星Galaxy ACE(GT-S5830B)和三星Galaxy 5(GT-I5500B)。提前谢谢,

1 个答案:

答案 0 :(得分:17)

stracktrace的第一行给你一个线索:

java.lang.NoSuchMethodError: java.io.IOException.<init>

基本上它说IOException的某些构造函数丢失了。查看javadocs,API级别9中添加了两个构造函数:

public IOException (Throwable cause)
public IOException (String message, Throwable cause)

那应该回答你的问题。 API级别9是Android 2.3。因此,堆栈跟踪来自运行Android 2.2或更低版本的设备,缺少上面的两个构造函数。

至少有两种解决方案可以解决这个问题:

  • 将应用清单中的minSdkVersion更改为9
  • 请勿使用最新的Google Play服务库,而是使用Froyo版本。

后者可以在SDK Manager中找到。它随last update一起添加,因为对Froyo(Android 2.2)的支持被删除了。引用链接的博客文章:

  

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