MapView:二进制XML文件第13行:二进制XML文件第13行:错误膨胀类

时间:2019-11-05 04:58:59

标签: java android

我正在使用MapVIew,该错误永远不会让我执行该应用程序。我一直在考虑解决方案几个小时,但无法解决此问题。我调查了类似的问题,但没有一个给我答案。我正在寻找此问题的解决方案。我在底部张贴了代码,错误消息和XML布局代码。

 public class Mainactivity extends FragmentActivity implements OnMapReadyCallback {
        private static final int LOCATION_REQUEST_CODE = 101;
        private GoogleMap mMap;



        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_mainactivity);

        }
        private void requestPermission(String permissionType,int requestCode ){
            ActivityCompat.requestPermissions(this,new String[]{permissionType},requestCode);
        }

        public void onRequestPermissionResult(int requestCode,String permissions[],int[]grantResults){
            switch (requestCode){
                case LOCATION_REQUEST_CODE: {
                    if (grantResults.length == 0 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
                        Toast.makeText(this, "Unable to show current location. You need to give us permission!", Toast.LENGTH_LONG).show();
                    } else {
                        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                                .findFragmentById(R.id.mapView2);
                        mapFragment.getMapAsync(this);
                    }
                }
            }
        }




        public void onMapReady(GoogleMap googleMap) {
            mMap = googleMap;


            if(mMap != null) {
                int permission = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
                if(permission == PackageManager.PERMISSION_GRANTED){
                    mMap.setMyLocationEnabled(true); }else{
                    requestPermission(
                            Manifest.permission.ACCESS_FINE_LOCATION,LOCATION_REQUEST_CODE);

                }}

            LatLng newOlympic = new LatLng(35.67946180000001, 139.71424260000003);




            Marker newOlympic1 = mMap.addMarker(new MarkerOptions()
                    .position(newOlympic)
                    .title("newOlympic")
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.photo_yoyogi_national_stadium)));

            mMap.moveCamera(CameraUpdateFactory.newLatLng(newOlympic));

        }}

错误代码如下。

E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.morimoku.location_activity, PID: 16042
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.morimoku.location_activity/com.morimoku.location_activity.Mainactivity}: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class MapView
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3092)
            at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
            at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1822)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:338)
            at android.app.ActivityThread.main(ActivityThread.java:6764)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
         Caused by: android.view.InflateException: Binary XML file line #13: Binary XML file line #13: Error inflating class MapView
         Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class MapView
         Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.MapView" on path: DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.morimoku.location_activity-ilWgqkKzr9e0rHn5NaPLJg==/base.apk"],nativeLibraryDirectories=[/data/app/com.morimoku.location_activity-ilWgqkKzr9e0rHn5NaPLJg==/lib/arm64, /system/lib64]]
            at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            at android.view.LayoutInflater.createView(LayoutInflater.java:606)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:703)
            at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:68)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:720)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:788)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
            at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:426)
            at android.app.Activity.setContentView(Activity.java:2771)
            at com.morimoku.location_activity.Mainactivity.onCreate(Mainactivity.java:108)
            at android.app.Activity.performCreate(Activity.java:7144)
            at android.app.Activity.performCreate(Activity.java:7135)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2937)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3092)
            at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
            at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1822)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:338)
            at android.app.ActivityThread.main(ActivityThread.java:6764)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

这是布局XML。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/framelayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Mainactivity">


    <MapView
        android:id="@+id/mapView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows. -->

</FrameLayout>

0 个答案:

没有答案