我是 Android 的新手,我正在尝试开发一个包含 Google map 的 Android 应用程序。在我决定将 Google Play 服务从版本 7 更新到版本 9 之前,该应用程序在模拟器上运行良好。
我现在遇到了与之前遇到的相同错误(“Google Play 服务已过期...”),以及“致命异常:主要”错误。这是我在 logcat 中得到的:
http://imageshack.us/a/img11/8117/y1mq.png
如果我正确阅读了 logcat,则错误在 MapTabActivity 中,但我不知道该错误是由于 Google Play 服务已过时还是其他原因造成的...
在更新 Google Play 服务之前,该应用程序在模拟器上运行
- Nexus 4 设备
- Android 4.2.2(API 等级 17)
- ARM 处理器
- 已选择主机 GPU
我还必须安装其他帖子中推荐的 com.android.vending.apk 和 com.google.android.gms.apk。
我还在 list 中添加了必要的权限,并申请了一个 API key ,该 key 也包含在 list 中。
谁能帮帮我?这是 MapTabActivity 及其对应的 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>
在此先感谢您提供的任何帮助。
最佳答案
我发现运行 Google Maps Android API v2 的唯一方法是在物理设备上。
我在装有 Android 4.0.4 的 Samsung Galaxy S Duos 上运行我的应用程序并且 map 显示正确。
在尝试了多种解决方案(包括测试多种模拟器配置和安装不同的 apk)之后,我相信在模拟器上使用 Google map API v2 时克服“Google Play 服务已过时”问题的最简单方法是在物理设备上开发/测试。
希望这对您有所帮助。
关于java - 模拟器上的 "Fatal Exception: main"和 "Google Play services out of date",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17742990/