简体   繁体   English

谷歌地图视图android.view.InflateException:二进制XML文件-错误夸大类片段

[英]Google maps view android.view.InflateException: Binary XML File - error inflating class fragment

This happened overnight after finishing this piece of code which pulls coordinates (Latitude and Longitude) from an API and displaying those coordinates with Markers onto a GoogleMap. 完成这段代码后,在一夜之间发生了这一段代码,该代码从API提取坐标(纬度和经度),并将带有Markers的坐标显示在GoogleMap上。 It was working fine until this morning when I decided to implement a refresh page code. 直到今天早上,当我决定实现刷新页面代码时,它的工作情况都还不错。 Even after I removed it just to double check, the error still remains. 即使我删除它只是为了再次检查,错误仍然存​​在。

I need help to understand what is going on, and how can I solve this issue. 我需要帮助以了解发生了什么,以及如何解决此问题。

XML XML格式

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.muhd.findtaxi.MapsActivity" >

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


</FrameLayout>

MapsActivity: MapsActivity:

import android.Manifest;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Handler;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.MarkerOptions;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    JSONParser jsonParser = new JSONParser();
    private GoogleMap mMap;
    private GoogleMap nMap;
    private static final LatLng Tampines = new LatLng(1.3525,103.9446);
    List<TaxiCoordinates> myCoordinates = new ArrayList<TaxiCoordinates>();
    private ProgressDialog pDialog;
    MapsActivity map;
    private static final String apiURL = "http://datamall2.mytransport.sg/ltaodataservice/TaxiAvailability/";
    private Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        MapFragment mapFragment = (MapFragment) getFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        myCoordinates = new ArrayList<TaxiCoordinates>();
        new GetCoordinates().execute();


    }
    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(Tampines, 10));

        // Add a marker in Sydney and move the camera
        // LatLng sydney = new LatLng(-34, 151);
        // mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        // mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }

    class GetCoordinates extends AsyncTask<String, String, JSONArray> {
        private ProgressDialog progressDialog;

        @Override
        protected JSONArray doInBackground(String... params)
        {
            try {
                JSONArray json = jsonParser.makeHttpRequest(
                        apiURL, "GET");

                if (json != null) {
                    Log.d("JSON result", json.toString());

                    return json;
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        }
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressDialog = new ProgressDialog(MapsActivity.this);
            progressDialog.setMessage("Loading Taxis...");
            progressDialog.show();
        }

        @Override
        protected void onPostExecute(JSONArray jsonArray) {

            if (jsonArray != null)
            {
                //loop
                for(int i = 0; i < jsonArray.length(); i++)
                {
                    try
                    {
                        JSONObject c = jsonArray.getJSONObject(i);
                        TaxiCoordinates temp = new TaxiCoordinates();
                        temp.setLatitude(c.getDouble("Latitude"));
                        temp.setLongitude(c.getDouble("Longitude"));
                        myCoordinates.add(temp);
                        if(progressDialog!=null && progressDialog.isShowing())
                        {
                            progressDialog.dismiss();
                        }

                    }
                    catch (JSONException e)
                    {
                        e.printStackTrace();
                    }
                }
                addMarkers();
            }
        }
    }



    public void addMarkers()
    {
        for(TaxiCoordinates c: myCoordinates)
        {
            double tempLat = c.getLatitude();
            double tempLong = c.getLongitude();
            LatLng pos = new LatLng(tempLat, tempLong);
            mMap.addMarker(new MarkerOptions()
                    .position(pos)
                    .title("Available")
                    .snippet("")
                    .icon(BitmapDescriptorFactory.defaultMarker()));

            //MarkerOptions m =  new MarkerOptions().title("Available").position(new LatLng(tempLat, tempLong));
            //googleMap.addMarker(m);
        }
    }
}

Android Manifest: Android清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.muhd.findtaxi">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>

    <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".RegisterActivity" />
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSyCqGKEImOEKNJO3e1WL2Ex7_NCUbKFD4D8" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps" />
        <activity android:name=".HomeActivity"></activity>
    </application>

</manifest>

EDIT: error points to line 54 in my MapsActivity: setContentView(R.layout.activity_maps); 编辑:错误指向我的MapsActivity中的第54行: setContentView(R.layout.activity_maps);

EDIT2: LOGCAT added EDIT2:LOGCAT已添加

02-24 05:23:00.785 14648-14648/com.example.muhd.findtaxi D/ChimeraCfgMgr: Reading stored module config
02-24 05:23:00.867 14648-14648/com.example.muhd.findtaxi D/ChimeraCfgMgr: Loading module com.google.android.gms.maps from APK /data/user/0/com.google.android.gms/app_chimera/chimera-module-root/module-a3e4fba11e705727c59ff3116ef21fa4834b9f56/MapsModule.apk
02-24 05:23:00.868 14648-14648/com.example.muhd.findtaxi D/ChimeraModuleLdr: Loading module APK /data/user/0/com.google.android.gms/app_chimera/chimera-module-root/module-a3e4fba11e705727c59ff3116ef21fa4834b9f56/MapsModule.apk
02-24 05:23:00.875 14648-14648/com.example.muhd.findtaxi D/ChimeraFileApk: Primary ABI of requesting process is x86
02-24 05:23:00.876 14648-14648/com.example.muhd.findtaxi D/ChimeraFileApk: Classloading successful. Optimized code found.
02-24 05:23:00.893 14648-14648/com.example.muhd.findtaxi W/System: ClassLoader referenced unknown path: /data/user/0/com.google.android.gms/app_chimera/chimera-module-root/module-a3e4fba11e705727c59ff3116ef21fa4834b9f56/native-libs/x86
02-24 05:23:01.097 14648-14648/com.example.muhd.findtaxi I/Google Maps Android API: Google Play services client version: 8487000
02-24 05:23:01.124 14648-14648/com.example.muhd.findtaxi I/Google Maps Android API: Google Play services package version: 8489470
02-24 05:23:01.262 14648-14659/com.example.muhd.findtaxi I/art: Background sticky concurrent mark sweep GC freed 5319(424KB) AllocSpace objects, 4(80KB) LOS objects, 12% free, 4MB/5MB, paused 14.765ms total 38.234ms
02-24 05:23:01.427 14648-14659/com.example.muhd.findtaxi I/art: Background sticky concurrent mark sweep GC freed 4766(238KB) AllocSpace objects, 0(0B) LOS objects, 4% free, 5MB/5MB, paused 6.657ms total 31.136ms
02-24 05:23:01.518 14648-14659/com.example.muhd.findtaxi I/art: Background partial concurrent mark sweep GC freed 1924(168KB) AllocSpace objects, 1(56KB) LOS objects, 39% free, 5MB/8MB, paused 5.994ms total 38.896ms
02-24 05:23:01.567 14648-14648/com.example.muhd.findtaxi W/ContextImpl: Failed to ensure /sdcard/Android/data/com.example.muhd.findtaxi/cache: java.lang.SecurityException: Invalid mkdirs path: /storage/self/primary/Android/data/com.example.muhd.findtaxi/cache
02-24 05:23:01.572 14648-14648/com.example.muhd.findtaxi D/AndroidRuntime: Shutting down VM
02-24 05:23:01.574 14648-14648/com.example.muhd.findtaxi E/AndroidRuntime: FATAL EXCEPTION: main
                                                                           Process: com.example.muhd.findtaxi, PID: 14648
                                                                           java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.muhd.findtaxi/com.example.muhd.findtaxi.MapsActivity}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                               at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                               at android.os.Looper.loop(Looper.java:148)
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                               at java.lang.reflect.Method.invoke(Native Method)
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                            Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment
                                                                               at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                               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:393)
                                                                               at android.app.Activity.setContentView(Activity.java:2166)
                                                                               at com.example.muhd.findtaxi.MapsActivity.onCreate(MapsActivity.java:53)
                                                                               at android.app.Activity.performCreate(Activity.java:6237)
                                                                               at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                               at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                               at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                               at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                               at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                               at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                               at android.os.Looper.loop(Looper.java:148) 
                                                                               at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                               at java.lang.reflect.Method.invoke(Native Method) 
                                                                               at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                               at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                                                                            Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
                                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
                                                                               at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
                                                                               at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
                                                                               at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798..

Just take 2 steps and problem would be more likely to get solved: 只需采取两个步骤,问题就更有可能得到解决:

Step 1: Clean your project by clicking Project -> Clean. 步骤1:通过单击项目->清理来清理项目。

Step 2: Rebuild your project by clicking Project -> Build All. 步骤2:通过单击Project-> Build All来重建项目。

Also make sure that your layout xml files are syntax error free and you don't have any image which has non-acceptable names (such as a "-" between image name). 另外,请确保您的布局xml文件没有语法错误,并且没有任何名称不可接受的图像(例如图像名称之间的“-”)。

Also I request you to have a look at problems window and let me know what errors are being shown there. 另外,我要求您查看问题窗口,让我知道那里显示的错误。

see this link Error inflating class fragment 看到此链接错误膨胀类片段

If you want Map inside a Fragment. 如果要在片段内映射。

You should use a MapView 您应该使用MapView

http://developer.android.com/reference/com/google/android/gms/maps/MapView.html http://developer.android.com/reference/com/google/android/gms/maps/MapView.html

暂无
暂无

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

相关问题 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文件第7行:二进制XML文件第7行:夸大类片段的错误 - android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment android.view.InflateException:二进制XML文件:错误膨胀类 - android.view.InflateException: Binary XML file: Error inflating class Android调试错误android.view.InflateException:二进制XML文件第9行:夸大类片段的错误 - Android debugging error android.view.InflateException: Binary XML file line #9: Error inflating class fragment Android-android.view.InflateException:二进制XML文件第9行:膨胀类片段的错误 - Android - android.view.InflateException: Binary XML file line #9: Error inflating class fragment 我遇到错误,显示通过 android.view.InflateException 对 class 片段进行膨胀时出错:二进制 XML 文件 - i am having error that shows Error inflating class fragment by android.view.InflateException: Binary XML file android.view.InflateException:二进制XML文件行#8:错误膨胀类片段 - android.view.InflateException: Binary XML file line #8: Error inflating class fragment 无法膨胀android.view.InflateException:二进制XML文件第24行:膨胀类片段时出错 - Failed to inflate android.view.InflateException: Binary XML file line #24: Error inflating class fragment android.view.InflateException:二进制XML文件第91行:错误放大了类片段 - android.view.InflateException: Binary XML file line #91: Error inflating class fragment RuntimeException:android.view.InflateException:二进制XML文件第8行:夸大类片段的错误 - RuntimeException : android.view.InflateException: Binary XML file line #8: Error inflating class fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM