Android google maps v2未知错误

时间:2014-02-13 15:39:05

标签: android api google-maps android-fragments api-key

我试着在他的开发者页面

上制作这个样本

https://developers.google.com/maps/documentation/android/start?hl=tr#obtain_a_google_maps_api_key

这是我的java代码:

package com.example.mapdemo;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity extends Activity {

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

和xml代码:

   <?xml version="1.0" encoding="utf-8"?>
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/map"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:name="com.google.android.gms.maps.MapFragment"/>

但如果我尝试在REAL DEVICE上执行此操作,Log cat会说:

  02-13 17:28:59.327: W/dalvikvm(12793): threadid=1: thread exiting with uncaught exception (group=0x410c02a0)
    02-13 17:28:59.327: E/AndroidRuntime(12793): FATAL EXCEPTION: main
    02-13 17:28:59.327: E/AndroidRuntime(12793): java.lang.RuntimeException: 
Unable to start activity
ComponentInfo{com.restroomgames.urfarehberi/com.restroomgames.urfarehberi.MainActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class fragment

也:

 02-13 17:28:59.327: E/AndroidRuntime(12793): Caused by: 
android.app.Fragment$InstantiationException: Unable to instantiate fragment 
com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an
 empty constructor that is public

也:

    02-13 17:28:59.327: E/AndroidRuntime(12793): Caused by:
 java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment

此视频帮助了我:https://www.youtube.com/watch?v=fitjMdZ8jqM 我认为问题是Debug.keystore或谷歌播放服务,因为我改变了它们,问题就消失了。

我也在我的网页上写了解决方案:

http://restroomgames.com/blog.php?ID=27

2 个答案:

答案 0 :(得分:0)

您无法在模拟器中测试Google地图。它没有Google Play服务。

答案 1 :(得分:0)

似乎你使用错误的模式进行充气。

java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.restroomgames.urfarehberi/com.restroomgames.urfarehberi.MainActivity}:
android.view.InflateException: Binary XML file line #2: Error inflating class fragmen

看看这个解决方案: https://stackoverflow.com/a/15137231/2523005