【发布时间】:2014-02-13 15:39:05
【问题描述】:
我尝试在他的开发者页面上制作这个示例
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 或 google play 服务,因为我更改了它们,问题就消失了。
我也在我的网页上写了解决方案:
【问题讨论】:
标签: android api google-maps android-fragments api-key