0
我想構建一個使用Google Maps Android API v2的Android應用程序。所以,我跟着鏈接 - Link。 按照鏈接中規定的步驟,我可以生成API密鑰。進一步完成後,我試圖運行該應用程序的步驟。我面臨以下錯誤。使用Google Maps創建Android應用程序Android API v2
04-05 10:01:56.442: E/AndroidRuntime(6170): FATAL EXCEPTION: main
04-05 10:01:56.442: E/AndroidRuntime(6170): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.task/com.example.task.MainActivity}: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2142)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2167)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.ActivityThread.access$600(ActivityThread.java:134)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.os.Looper.loop(Looper.java:150)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.ActivityThread.main(ActivityThread.java:4831)
04-05 10:01:56.442: E/AndroidRuntime(6170): at java.lang.reflect.Method.invokeNative(Native Method)
04-05 10:01:56.442: E/AndroidRuntime(6170): at java.lang.reflect.Method.invoke(Method.java:511)
04-05 10:01:56.442: E/AndroidRuntime(6170): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-05 10:01:56.442: E/AndroidRuntime(6170): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-05 10:01:56.442: E/AndroidRuntime(6170): at dalvik.system.NativeStart.main(Native Method)
04-05 10:01:56.442: E/AndroidRuntime(6170): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class fragment
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-05 10:01:56.442: E/AndroidRuntime(6170): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:257)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.Activity.setContentView(Activity.java:1867)
04-05 10:01:56.442: E/AndroidRuntime(6170): at com.example.task.MainActivity.onCreate(MainActivity.java:14)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.Activity.performCreate(Activity.java:5008)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
04-05 10:01:56.442: E/AndroidRuntime(6170): ... 11 more
04-05 10:01:56.442: E/AndroidRuntime(6170): 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
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.Fragment.instantiate(Fragment.java:584)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.Fragment.instantiate(Fragment.java:552)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.Activity.onCreateView(Activity.java:4656)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
04-05 10:01:56.442: E/AndroidRuntime(6170): ... 21 more
04-05 10:01:56.442: E/AndroidRuntime(6170): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
04-05 10:01:56.442: E/AndroidRuntime(6170): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-05 10:01:56.442: E/AndroidRuntime(6170): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-05 10:01:56.442: E/AndroidRuntime(6170): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-05 10:01:56.442: E/AndroidRuntime(6170): at android.app.Fragment.instantiate(Fragment.java:574)
04-05 10:01:56.442: E/AndroidRuntime(6170): ... 24 more
錯誤可能是因爲com.google.android.gms.maps.MapFragment包在main.xml中的。 我有com.google.android.gms封裝在我的DUT中,但無法找到com.google.android.gms.maps.MapFragment。我怎麼知道這個軟件包是否在我的DUT中,以及錯誤的解決方案是什麼。
我成功了一點,但現在eclipse正在拋出一個新的錯誤 - 「無法連接到谷歌服務器」。此外,我能夠在應用中看到放大/縮小選項,但地圖圖塊不會顯示在屏幕上。任何關於這個的想法! – 2013-04-12 04:54:15
現在,我可以在我的應用程序中看到地圖。我在生成API密鑰時使用了錯誤的軟件包。 – 2013-04-15 09:02:49
@YugalKothari,很好,你有一個很好的代碼:) – 2013-04-15 10:40:23