“Fatal Exception: main” and “Google Play services out of date” on emulator

ぐ巨炮叔叔 提交于 2019-12-11 11:48:01

问题


I am new to Android and I am trying to develop an android app that includes Google maps. The app was working fine on the emulator until I decided to update the Google Play services from revision 7 to 9.

I now get the same error I encountered before ("Google Play services is out of date..."), plus a "fatal exception: main" error. Here is what I get in the logcat:

http://imageshack.us/a/img11/8117/y1mq.png

If I read the logcat correctly, the error is in the MapTabActivity but I don't know if the error is caused by the Google Play services being out of date or if it's something else...

Before updating the Google Play services, the app was working on an emulator with

  • Nexus 4 device
  • Android 4.2.2(API lvl 17)
  • ARM CPU
  • Host GPU selected

I also had to install the com.android.vending.apk and com.google.android.gms.apk that was recommend in other posts about this.

I also added the permission necessary to the manifest and applied for an API key which is also included in the manifest.

Can anyone help me? Here's the MapTabActivity and its corresponding XML.

MapTabActivity.java

package com.dissertation.closethedoordiss;

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.LatLng;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;

public class MapTabActivity extends FragmentActivity {

private GoogleMap mMap;
private static final LatLng BRISTOL = new LatLng(51.455083,-2.586903);

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maptab);


    mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapView)).getMap();
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(BRISTOL, 13));
}

public void onClick_addretailer (View view) {
    startActivity(new Intent("com.closethedoordiss.AddRetailerActivity"));
}  
}

activity_maptab.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <fragment
        android:name="com.google.android.gms.maps.SupportMapFragment" 
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />



  <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:src="@android:drawable/ic_menu_add"
        android:onClick="onClick_addretailer"
        android:contentDescription="@string/add_button" />

</RelativeLayout>

Thanks in advance for any help provided.


回答1:


The only way I have found to run Google Maps Android API v2 is on a physical device.

I am running my app on a Samsung Galaxy S Duos with Android 4.0.4 and the map is displaying correctly.

After trying several solutions, including testing several emulator configurations and installing different apks, I believe the easiest way to overcome the "Google Play Services is out of date" issue when it comes to using Google maps API v2 on an emulator is to develop/test on a physical device.

Hope this helps.




回答2:


I've had this issue many times and I've find a couple ways to resolve it. Most likely the Play Services that your app is referencing isn't matching up to what you have on the device, which in this case is the emulator. This might be happening because Google Play (or Google Play Services) isn't installed on the emulator. Check this SO post for more info. If it is installed, you may need to update it. You could update it by installing from scratch if the built-in updating doesn't work.

If you're using the Google Play Services as a library project, you may need to update your Google Play Services library. Here's what I do:

  • Open the SDK manager and see if there's an update to the Google Play Services
  • If there is, download it
  • In eclipse, delete your old Play Services project and import the new one
  • Re-add the new project as a reference

If you're not using the Google Play Services as a library project, or if you've alaready updated, then ignore everything I said above :)

Once your device/emulator and Eclipse project are using the same updated version of the Play Services library, then you should be good to go!



来源:https://stackoverflow.com/questions/17742990/fatal-exception-main-and-google-play-services-out-of-date-on-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!