我已经创建了谷歌地图 v2 应用程序。我一步一步地按照教程。当我启动这个应用程序时。
它显示弹出“不幸的是,Google Maps v2 已停止”。
这是日志猫...
09-03 04:51:33.296: E/AndroidRuntime(2148): FATAL EXCEPTION: main
09-03 04:51:33.296: E/AndroidRuntime(2148): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.achson.googlemapsv2/com.achson.googlemapsv2.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.os.Looper.loop(Looper.java:137)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-03 04:51:33.296: E/AndroidRuntime(2148): at java.lang.reflect.Method.invokeNative(Native Method)
09-03 04:51:33.296: E/AndroidRuntime(2148): at java.lang.reflect.Method.invoke(Method.java:525)
09-03 04:51:33.296: E/AndroidRuntime(2148): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-03 04:51:33.296: E/AndroidRuntime(2148): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-03 04:51:33.296: E/AndroidRuntime(2148): at dalvik.system.NativeStart.main(Native Method)
09-03 04:51:33.296: E/AndroidRuntime(2148): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-03 04:51:33.296: E/AndroidRuntime(2148): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Activity.setContentView(Activity.java:1895)
09-03 04:51:33.296: E/AndroidRuntime(2148): at com.achson.googlemapsv2.MainActivity.onCreate(MainActivity.java:18)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Activity.performCreate(Activity.java:5133)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-03 04:51:33.296: E/AndroidRuntime(2148): ... 11 more
09-03 04:51:33.296: E/AndroidRuntime(2148): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Fragment.instantiate(Fragment.java:585)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Fragment.instantiate(Fragment.java:560)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.app.Activity.onCreateView(Activity.java:4738)
09-03 04:51:33.296: E/AndroidRuntime(2148): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
09-03 04:51:33.296: E/AndroidRuntime(2148): ... 21 more
我假设 google-play-services 不在 Android Dependencies 文件夹中。
但它位于 Android Private Libraries 文件夹中。我不知道如何导入到 Android Dependencies 文件夹。有谁知道吗?请在此分享。
09-06 15:29:30.480: E/AndroidRuntime(1260): FATAL EXCEPTION: main
09-06 15:29:30.480: E/AndroidRuntime(1260): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.googlemapsv2/com.example.googlemapsv2.MainActivity}: java.lang.NullPointerException: CameraUpdateFactory is not initialized
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.os.Handler.dispatchMessage(Handler.java:99)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.os.Looper.loop(Looper.java:137)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-06 15:29:30.480: E/AndroidRuntime(1260): at java.lang.reflect.Method.invokeNative(Native Method)
09-06 15:29:30.480: E/AndroidRuntime(1260): at java.lang.reflect.Method.invoke(Method.java:511)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-06 15:29:30.480: E/AndroidRuntime(1260): at dalvik.system.NativeStart.main(Native Method)
09-06 15:29:30.480: E/AndroidRuntime(1260): Caused by: java.lang.NullPointerException: CameraUpdateFactory is not initialized
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.google.android.gms.internal.ac.a(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.google.android.gms.maps.CameraUpdateFactory.aV(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.google.android.gms.maps.CameraUpdateFactory.newLatLngZoom(Unknown Source)
09-06 15:29:30.480: E/AndroidRuntime(1260): at com.example.googlemapsv2.MainActivity.onCreate(MainActivity.java:24)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.Activity.performCreate(Activity.java:5104)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-06 15:29:30.480: E/AndroidRuntime(1260): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-06 15:29:30.480: E/AndroidRuntime(1260): ... 11 more