Android: How to track down the origin of a InflateException?
I had the same exact error. The only xml line 24 that made any sense was my application manifest which happened to be the closing tag for application. I traced it down to my custom theme I was adding for the app -- I was not defining the parent of the style. All I needed to do was add parent="android:Theme" to my style and my error went away.
<style name="MyTheme" parent="android:Theme">
...
</style>
android.view.InflateException: Binary XML file line #12: Error inflating class unknown
The inflate exception is not actually the problem but really comes from another deeper issue in your layout that is then wrapped in an InflateException
.
A common issue is an out of memory exception when trying to inflate an ImageView
loading a drawable resource. If one of these resources has a high pixel resolution it would take a lot of memory causing then an inflate exception.
So basically verify that the pixel resolution in all your image drawables is just the minimum necessary for your layout.
android.view.InflateException: Binary XML file: Error inflating class fragment
After long time for debugging, I have fixed this problem. (Although I still cannot explain why). That I change property android:name
to class
. (although on Android Document, they say those properties are same, but it works !!!)
So, it should change from :
android:name="com.fragment.NavigationDrawerFragment"
to
class = "com.fragment.NavigationDrawerFragment"
So, new layout should be :
<!-- As the main content view, the view below consumes the entire
space available using match_parent in both dimensions. -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- android:layout_gravity="start" tells DrawerLayout to treat
this as a sliding drawer on the left side for left-to-right
languages and on the right side for right-to-left languages.
If you're not building against API 17 or higher, use
android:layout_gravity="left" instead. -->
<!-- The drawer is given a fixed width in dp and extends the full height of
the container. -->
<fragment android:id="@+id/navigation_drawer"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
class = "com.fragment.NavigationDrawerFragment" />
Hope this help :)
Android: Inflate Exception after trying to add another language to my application
If you look through to the bottom of the log, you'll see that the root cause of the problem is:
Caused by: java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
at android.content.res.Resources.loadDrawable(Resources.java:1935)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.ImageView.<init>(ImageView.java:119)
at android.widget.ImageView.<init>(ImageView.java:109)
... 27 more
As this is happening on your splash screen, I'll make a guess that the Image you're loading is too large. Compare the image sizes in your English version and your Arabic version to see if the Arabic file is much larger than the English one. Try optimising the image, maybe, scale it down to reduce the size...
EDIT: On the second error:
Again, this is an OutOfMemory error. When you have errors like this, always look at the bottom-most Caused by
part. In this case you have:
Caused by: java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
at android.content.res.Resources.loadDrawable(Resources.java:1935)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.ImageView.<init>(ImageView.java:119)
at android.widget.ImageView.<init>(ImageView.java:109)
... 27 more
If you have reduced the size of your image, as you indicated, then it means that there's another large image somewhere.
Note that it's not the file size of your JPG or PNG file that matters, it's how much memory is needed to decode that image file internally. One way to estimate approximately how much memory is required to internally decode an image file is to open that file in an image editor and save it as uncompressed TIFF file. The size of the TIFF file is approximately how much memory decoded image will take in a running Android app. As a test, I just saved a 750KB JPG as a TIFF - and it turned out to be 5.8 MB.
android.view.InflateException Error inflating class android.webkit.WebView
If you use androidx.appcompat:appcompat:1.1.0
, try androidx.appcompat:appcompat:1.0.2
instead.
it seems that 1.1.0
doesn't fix the bug with WebView
in Android 5.1.1
.
Feb-2020 update: Reverting to 1.0.2
stopped working for many people (including my app), but using the current version of androidx.appcompat:appcompat:1.2.0-alpha02
did fix the crash. (I was seeing it on a Huawei P8 Lite running Android 5.0 during Google's automated "Pre-launch report" testing).
Jun-2020 update: There are newer releases available than the one mentioned in the Feb-2020 update, you can see the currently available versions here:
- https://developer.android.com/jetpack/androidx/releases/appcompat
Android - android.view.InflateException: Binary XML file line #8: Error inflating class fragment
Yes.. I want Map inside a Fragment.
You should use a MapView
http://developer.android.com/reference/com/google/android/gms/maps/MapView.html
public class HowToReach extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment2, container, false);
// Gets the MapView from the XML layout and creates it
try {
MapsInitializer.initialize(getActivity());
} catch (GooglePlayServicesNotAvailableException e) {
Log.e("Address Map", "Could not initialize google play", e);
}
switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) )
{
case ConnectionResult.SUCCESS:
Toast.makeText(getActivity(), "SUCCESS", Toast.LENGTH_SHORT).show();
mapView = (MapView) v.findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
if(mapView!=null)
{
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
map.animateCamera(cameraUpdate);
}
break;
case ConnectionResult.SERVICE_MISSING:
Toast.makeText(getActivity(), "SERVICE MISSING", Toast.LENGTH_SHORT).show();
break;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
Toast.makeText(getActivity(), "UPDATE REQUIRED", Toast.LENGTH_SHORT).show();
break;
default: Toast.makeText(getActivity(), GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()), Toast.LENGTH_SHORT).show();
}
// Updates the location and zoom of the MapView
return v;
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
}
fragment2.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:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map" />
</RelativeLayout>
Update:
https://developers.google.com/android/reference/com/google/android/gms/maps/MapView#public-constructors
getMap()
is deprecated. Use getMapAsync(OnMapReadyCallback)
instead. The callback method provides you with a GoogleMap instance guaranteed to be non-null and ready to be used.
InflateException: Error inflating class ImageView for VectorDrawableCompat
I believe the problem is android:src="@drawable/mypic"
in your imageView setup.
Change that toapp:srcCompat="@drawable/mypic"
Then you should be good to go.
More details, please refer to:
https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.mvuq06x1k
Related Topics
How to Hide Android Soft Keyboard on Edittext
How to Make Drawerlayout to Display Below the Toolbar
Rotate an Yuv Byte Array on Android
Google Maps Fragment Returning Null Inside a Fragment
Java.Lang.Noclassdeffounderror: Com.Google.Android.Gms.Internal.Zzmp
Getactionbar() Returns Null (Appcompat-V7 21)
Mapview Rendering with Tiles Missing with an "X" in the Center
Stuck with Getting Camera Pic When Using the Tab Activity
How to Change Color of Android Listview Separator Line
Getting Data from Android Play Store
Detect If App Was Downloaded from Android Market
Android-L Cardview Visual Touch Feedback
Developing an Android Homescreen
How to Import Eclipse Project to Android Studio