我正在开发一个简单的应用程序,它可以播放音乐并显示谷歌地图。当我尝试将地图放在主要活动中时,我得到“错误膨胀类片段”。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(MainActivity.LOG_TAG, "activity started");
gmap = ((MapFragment)getFragmentManager().findFragmentById(R.id.fragment1)).getMap();
music = new MusicServiceWrapper(this);
}
这是布局文件的一部分
<fragment
android:id="@+id/fragment1"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/linearLayout1"
android:layout_alignLeft="@+id/linearLayout2" />
关于我为什么会收到此错误的任何想法?
编辑:我将包含一些来自 LogCat 的错误(第 132 行是指我给出的 xml 片段的第一行)
04-01 01:43:35.972: E/Trace(625): error opening trace file: No such file or directory (2)
04-01 01:43:36.572: D/AndroidRuntime(625): Shutting down VM
04-01 01:43:36.572: W/dalvikvm(625): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
04-01 01:43:36.582: E/AndroidRuntime(625): FATAL EXCEPTION: main
04-01 01:43:36.582: E/AndroidRuntime(625): java.lang.RuntimeException: Unable to start activity ComponentInfo{net.kenpowers.gea/net.kenpowers.gea.MainActivity}: android.view.InflateException: Binary XML file line #132: Error inflating class fragment
04-01 01:43:36.582: E/AndroidRuntime(625): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-01 01:43:36.582: E/AndroidRuntime(625): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-01 01:43:36.582: E/AndroidRuntime(625): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-01 01:43:36.582: E/AndroidRuntime(625): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-01 01:43:36.582: E/AndroidRuntime(625): at android.os.Handler.dispatchMessage(Handler.java:99)
04-01 01:43:36.582: E/AndroidRuntime(625): at android.os.Looper.loop(Looper.java:137)
04-01 01:43:36.582: E/AndroidRuntime(625): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-01 01:43:36.582: E/AndroidRuntime(625): at java.lang.reflect.Method.invokeNative(Native Method)
04-01 01:43:36.582: E/AndroidRuntime(625): at java.lang.reflect.Method.invoke(Method.java:511)
04-01 01:43:36.582: E/AndroidRuntime(625): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-01 01:43:36.582: E/AndroidRuntime(625): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-01 01:43:36.582: E/AndroidRuntime(625): at dalvik.system.NativeStart.main(Native Method)
04-01 01:43:36.582: E/AndroidRuntime(625): Caused by: android.view.InflateException: Binary XML file line #132: Error inflating class fragment
04-01 01:43:36.582: E/AndroidRuntime(625): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-01 01:43:36.582: E/AndroidRuntime(625): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)