简体   繁体   English

android.view.InflateException:二进制XML文件行#6:错误导致类com.google.android.gms.maps.MapView

[英]android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.gms.maps.MapView

I was trying to implement a mapview in a fragment with viewpager but despite I tried many solutions, I couldn't find the correct one for my project. 我试图用viewpager在片段中实现mapview,但是尽管我尝试了很多解决方案,但我找不到适合我项目的正确解决方案。

Here is my logcat 这是我的logcat

2019-05-26 17:28:16.645 12469-12469/com.example.emrullah.booksharingappv4 E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.emrullah.booksharingappv4, PID: 12469
    android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class com.google.android.gms.maps.MapView
    Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.gms.maps.MapView
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
        at android.view.LayoutInflater.createView(LayoutInflater.java:651)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
        at com.example.emrullah.booksharingappv4.Fragments.MapviewFragment.onCreateView(MapviewFragment.java:50)
        at android.support.v4.app.Fragment.performCreateView(Fragment.java:2439)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
        at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2243)
        at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:654)
        at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:146)

here is my fragment 这是我的片段

public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.mapview_fragment, container, false);

        mLocationList= new ArrayList<>();
        mLocList= new ArrayList<>();
        mLocList2= new ArrayList<>();
        mRef=FirebaseDatabase.getInstance().getReference().child("users");
        currentUser=FirebaseAuth.getInstance().getCurrentUser();
        getLatLongFromDb();
        split(mLocList);

        mMapView = view.findViewById(R.id.map_view);
        mMapView.onCreate(savedInstanceState);

        mMapView.onResume();

        try {
            MapsInitializer.initialize(getActivity().getApplicationContext());
        } catch (Exception e) {
            e.printStackTrace();
        }

        //Gets the Googlemap from Mapview and does the initialization stuff
        mMapView.getMapAsync(new OnMapReadyCallback() {
            @Override
            public void onMapReady(GoogleMap googleMap) {
                mMap = googleMap;
                mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);


                for (int i = 0;i<mLocList2.size();i++){
                    LatLng sydney = new LatLng(mLocList2.get(i),mLocList2.get(i+1));
                    mMap.addMarker(new MarkerOptions().position(sydney).title("Book dest:"+(i+1)));
                }
            }
        });


        return view;
    }
    @Override
    public void onResume() {
        super.onResume();

        if (mMapView != null)
            mMapView.onResume();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();

        if (mMapView != null)
            mMapView.onDestroy();
    }


    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);

        if (mMapView != null)
            mMapView.onSaveInstanceState(outState);
    }
}

Here is my xml file 这是我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.gms.maps.MapView
        android:id="@+id/map_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.example.emrullah.booksharingappv4.Fragments.MapviewFragment"
        />
</RelativeLayout>

And viewPager part in the Activity 并且Activity中的viewPager部分

public void setupViewPager(ViewPager viewPager) {
        SectionPageAdapter sectionPageAdapter = new SectionPageAdapter(getSupportFragmentManager());
        sectionPageAdapter.addFragment(new BookListFragment(), "BOOKS");
        sectionPageAdapter.addFragment(new MapviewFragment(), "BOOK MAP");
        sectionPageAdapter.addFragment(new SettingsFragment(), "SETTINGS");
        viewPager.setAdapter(sectionPageAdapter);
    }
    public void setUpTabIcons(){
        tabLayout.getTabAt(0).setIcon(navIcons[0]);
        tabLayout.getTabAt(1).setIcon(navIcons[1]);
        tabLayout.getTabAt(2).setIcon(navIcons[2]);
    }

I know there are some similar questions like mine but I tried all of them and none of them worked. 我知道有一些像我这样的类似问题,但我尝试了所有这些问题,但没有一个能够奏效。 Thanks for the help. 谢谢您的帮助。

You are attempting to use the original version of Google Maps support for Android (com.google.android.maps). 您正在尝试使用Android版Google地图支持的原始版本(com.google.android.maps)。 We refer to that now as Maps V1. 我们现在称之为地图V1。

This will not work, as Maps V1 has been deprecated for over 4 years. 这不起作用,因为地图V1已被弃用超过4年。 You can no longer get API keys for it, so even if your code would be correct, it would not work. 你不能再获得它的API密钥,所以即使你的代码是正确的,它也行不通。 The crash is because the old MapView had to be used inside of a MapActivity, as the error indicates. 崩溃是因为旧的MapView必须在MapActivity中使用,如错误所示。

The current version of Google Maps support for Android — Maps V2 — has a very different API and does not involve classes in the com.google.android.maps package. 当前版本的Google地图支持Android - Maps V2 - 具有非常不同的API,并且不涉及com.google.android.maps包中的类。

please read how to use Maps V2 form the official documentation 请阅读如何使用Maps V2形式的官方文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 膨胀类com.google.android.gms.maps.MapView时出错 - Error inflating class com.google.android.gms.maps.MapView 谷歌地图视图android.view.InflateException:二进制XML文件-错误夸大类片段 - Google maps view android.view.InflateException: Binary XML File - error inflating class fragment android.view.InflateException:二进制XML文件第9行错误,导致类com.hamweather.aeris.maps.AerisMapView膨胀 - android.view.InflateException: Binary XML file line #9 error inflating class com.hamweather.aeris.maps.AerisMapView 原因:android.view.InflateException:二进制XML文件第16行:膨胀类com.google.android.material.navigation.NavigationView时出错 - Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.google.android.material.navigation.NavigationView android.view.InflateException:二进制XML文件第6行:二进制XML文件第6行:膨胀类错误 - android.view.InflateException: Binary XML file line #6: Binary XML file line #6: Error inflating class android.view.InflateException:二进制XML文件第0行:二进制XML文件第0行:膨胀类错误<Classname> - android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <Classname> android.view.InflateException:二进制XML文件第0行:二进制XML文件第0行:膨胀类片段时出错 - android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment android.view.InflateException:二进制 XML 文件第 9 行:二进制 XML 文件第 9 行:错误膨胀类 - android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.view.InflateException:二进制XML文件第7行:二进制XML文件第7行:夸大类片段的错误 - android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment android.view.InflateException:二进制 XML 文件第 2 行:二进制 XML1 文件第 2 行:错误充气 Z3501BB4F2AC9CDC80<unknown></unknown> - android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM