我有 MainActivity 类,它有实例化 ApplicationBar 的方法,所有其他活动都是从这个继承的,MainActivity
所以他们可以使用这个方法。
但我也有一个类 MapHolder,它必须从FragmentActivity
xml 扩展,它使用 afragment
来显示地图。问题是,如果我从FragmentActivity
无法显示 ApplicationBar 选项卡中扩展它,并且如果我从 MainActivity 扩展它,则无法显示地图,并且会出现此错误:
LogCat Output:
09-29 17:52:10.107: E/GooglePlayServicesUtil(3788): Google Play services is invalid. Cannot recover.
09-29 17:52:43.536: E/AndroidRuntime(3832): FATAL EXCEPTION: main
09-29 17:52:43.536: E/AndroidRuntime(3832): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mydomain.myproj/com.mydomain.myproj.MapHolder }: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.os.Handler.dispatchMessage(Handler.java:99)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.os.Looper.loop(Looper.java:137)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.ActivityThread.main(ActivityThread.java:5103)
09-29 17:52:43.536: E/AndroidRuntime(3832): at java.lang.reflect.Method.invokeNative(Native Method)
09-29 17:52:43.536: E/AndroidRuntime(3832): at java.lang.reflect.Method.invoke(Method.java:525)
09-29 17:52:43.536: E/AndroidRuntime(3832): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
09-29 17:52:43.536: E/AndroidRuntime(3832): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
09-29 17:52:43.536: E/AndroidRuntime(3832): at dalvik.system.NativeStart.main(Native Method)
09-29 17:52:43.536: E/AndroidRuntime(3832): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
09-29 17:52:43.536: E/AndroidRuntime(3832): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.Activity.setContentView(Activity.java:1895)
09-29 17:52:43.536: E/AndroidRuntime(3832): at com.mydomain.myproj.MapHolder .onCreate(MapHolder .java:19)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.Activity.performCreate(Activity.java:5133)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
09-29 17:52:43.536: E/AndroidRuntime(3832): ... 11 more
09-29 17:52:43.536: E/AndroidRuntime(3832): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.Fragment.instantiate(Fragment.java:585)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.Fragment.instantiate(Fragment.java:560)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.app.Activity.onCreateView(Activity.java:4738)
09-29 17:52:43.536: E/AndroidRuntime(3832): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
09-29 17:52:43.536: E/AndroidRuntime(3832): ... 20 more