Google maps view android.view.InflateException: двоичный XML-файл - ошибка раздувания фрагмента класса
Это произошло в одночасье после завершения этого фрагмента кода, который извлекает координаты (широта и долгота) из API и отображает эти координаты с маркерами в GoogleMap. Это работало нормально до сегодняшнего утра, когда я решил реализовать код обновления страницы. Даже после того, как я удалил его только для двойной проверки, ошибка все еще остается.
Мне нужна помощь, чтобы понять, что происходит, и как я могу решить эту проблему.
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:
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:
<?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>
РЕДАКТИРОВАТЬ: ошибка указывает на строку 54 в моей MapsActivity: setContentView(R.layout.activity_maps);
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..
2 ответа
Если вы хотите карту внутри фрагмента.
Вы должны использовать MapView
http://developer.android.com/reference/com/google/android/gms/maps/MapView.html
Просто сделайте 2 шага, и проблема, скорее всего, будет решена:
Шаг 1: Очистите ваш проект, нажав Project -> Clean.
Шаг 2: Перестройте свой проект, нажав Project -> Build All.
Также убедитесь, что XML-файлы макета не содержат синтаксических ошибок, и у вас нет изображения с недопустимыми именами (например, "-" между именем изображения).
Также я прошу вас взглянуть на окно проблем и сообщить, какие ошибки там отображаются.
смотрите эту ссылку Ошибка надувания фрагмента класса