Android 扩展另一个扩展ActionBarActivity的活动中的映射片段膨胀错误

Android 扩展另一个扩展ActionBarActivity的活动中的映射片段膨胀错误,android,google-maps,android-fragments,Android,Google Maps,Android Fragments,我知道这个标题毫无意义。 问题是我有一个扩展ActionBarActivity的主活动(它包含所有活动中共享的所有代码);我有另一个扩展主活动的活动;最后一个活动包含一个映射片段;我添加了所有必需的代码,但在“设置内容”视图中出现错误 有人能帮忙吗?我可以补充什么来帮助您理解我的问题 编辑: 这是密码。我遗漏了很多我认为不相关的东西 MainLayoutActivity.java: public class MainLayoutActivity extends ActionBarActivity

我知道这个标题毫无意义。 问题是我有一个扩展ActionBarActivity的主活动(它包含所有活动中共享的所有代码);我有另一个扩展主活动的活动;最后一个活动包含一个映射片段;我添加了所有必需的代码,但在“设置内容”视图中出现错误

有人能帮忙吗?我可以补充什么来帮助您理解我的问题

编辑:

这是密码。我遗漏了很多我认为不相关的东西

MainLayoutActivity.java:

public class MainLayoutActivity extends ActionBarActivity {

    @Override
    public void setContentView(int id) {


        LinearLayout linearLayoutContent = (LinearLayout) findViewById(R.id.linearLayoutContent);
        LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(id, linearLayoutContent); //linrstlayoutcontent is the linearlayout that will contain the content 

    }

}
activity_main_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawerLayoutMenu"
    android:layout_width="match_parent"
    android:layout_height="match_parent" > 
    <FrameLayout
        android:id="@+id/frameLayoutContent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:id="@+id/linearLayoutContent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/bgColor"
                android:orientation="vertical" >
            </LinearLayout>

        </RelativeLayout>
    </FrameLayout> 

    <ListView
        android:id="@+id/MainMenu"
        style="@style/MainMenu"
        android:background="@color/LeftMenuBackground"
        android:divider="@drawable/menu_separator" />


</android.support.v4.widget.DrawerLayout>
activity_club_details.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"  >


                <fragment
                    android:id="@+id/map"
                    android:name="com.google.android.gms.maps.SupportMapFragment"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />


 </LinearLayout>

谢谢你

我不知道你为什么会得到ClassNotFoundException。您的构建中似乎缺少支持库。如果构建路径设置正确,请再次检查此页面。还要检查您是否没有将来自支持库的片段与本机片段混合

除此之外,即使您修复了
ClassNotFoundException
,您的应用程序也不会工作。在
MainLayoutActivity setContentView
中,您缺少调用
super.setContentView(R.layout.activity\u main\u activity.xml)


目前,由于未设置布局,
linearLayoutContent
将始终为空。

从sdk管理器更新Google Play库

private void checkForMap() {
    try {
        // Getting Google Play availability status
        int status = GooglePlayServicesUtil
                .isGooglePlayServicesAvailable(mContext);

        // Showing status
        if (status != ConnectionResult.SUCCESS) {
            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status,
                    this, requestCode);
            dialog.show();

        } else { // Google Play Services are available

            // Getting reference to the SupportMapFragment of
            // activity_main.xml
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            // map = ((MapFragment)
            // getFragmentManager().findFragmentById(R.id.map)).getMap();

            // Getting GoogleMap object from the fragment
            googleMap = fm.getMap();
        }

        googleMap.setOnInfoWindowClickListener(this);
    } catch (Exception exception) {
        DebugHelper.printException(exception);
    }
}

GoogleMapV2总是通过片段活动进行扩展,因为xml布局文件中的映射部分是通过片段显示的。因此,您应该使用扩展GoogleMap的片段活动。有关google map v2的说明,请查看以下链接:

请发布stacktrace和相关代码。@Emmanuel我发布了您要求的内容。这有帮助吗?问题已经问过了。试试这个答案:
05-19 19:30:50.961: E/AndroidRuntime(20934): FATAL EXCEPTION: main
05-19 19:30:50.961: E/AndroidRuntime(20934): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.borninteractive.fitnesstime/com.borninteractive.fitnesstime.ClubDetailsActivity}: android.view.InflateException: Binary XML file line #164: Error inflating class fragment
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2249)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.access$700(ActivityThread.java:154)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.os.Looper.loop(Looper.java:137)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.main(ActivityThread.java:5306)
05-19 19:30:50.961: E/AndroidRuntime(20934): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 19:30:50.961: E/AndroidRuntime(20934): at java.lang.reflect.Method.invoke(Method.java:511)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
05-19 19:30:50.961: E/AndroidRuntime(20934): at dalvik.system.NativeStart.main(Native Method)
05-19 19:30:50.961: E/AndroidRuntime(20934): Caused by: android.view.InflateException: Binary XML file line #164: Error inflating class fragment
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.borninteractive.fitnesstime.MainLayoutActivity.setContentView(MainLayoutActivity.java:237)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.borninteractive.fitnesstime.ClubDetailsActivity.onCreate(ClubDetailsActivity.java:87)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.Activity.performCreate(Activity.java:5255)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213)
05-19 19:30:50.961: E/AndroidRuntime(20934): ... 11 more
05-19 19:30:50.961: E/AndroidRuntime(20934): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.fragment" on path: /data/app/com.borninteractive.fitnesstime-2.apk
05-19 19:30:50.961: E/AndroidRuntime(20934): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-19 19:30:50.961: E/AndroidRuntime(20934): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-19 19:30:50.961: E/AndroidRuntime(20934): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.createView(LayoutInflater.java:558)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:649)
05-19 19:30:50.961: E/AndroidRuntime(20934): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
05-19 19:30:50.961: E/AndroidRuntime(20934): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
05-19 19:30:50.961: E/AndroidRuntime(20934): ... 23 more
private void checkForMap() {
    try {
        // Getting Google Play availability status
        int status = GooglePlayServicesUtil
                .isGooglePlayServicesAvailable(mContext);

        // Showing status
        if (status != ConnectionResult.SUCCESS) {
            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status,
                    this, requestCode);
            dialog.show();

        } else { // Google Play Services are available

            // Getting reference to the SupportMapFragment of
            // activity_main.xml
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            // map = ((MapFragment)
            // getFragmentManager().findFragmentById(R.id.map)).getMap();

            // Getting GoogleMap object from the fragment
            googleMap = fm.getMap();
        }

        googleMap.setOnInfoWindowClickListener(this);
    } catch (Exception exception) {
        DebugHelper.printException(exception);
    }
}