My app crashed because
Error inflating class android.support.design.widget.FloatingActionButton
This is my code in the XML
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/icon_right"
app:backgroundTint="#color/green"
android:onClick="previewphoto"
app:layout_anchorGravity="bottom|right|end" />
and here is my gradle
compile 'com.android.support:appcompat-v7:23.4.0' // appcompat library
compile 'com.android.support:design:23.4.0'
my logcat
FATAL EXCEPTION: main Process: com.cyanlabsid.cetakphoto, PID: 15298
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.cyanlabsid.cetakphoto/com.cyanlabsid.cetakphoto.PhotoPicker}:
android.view.InflateException: Binary XML file line #76: Binary XML
file line #76: Error inflating class
android.support.design.widget.FloatingActionButton at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2423)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:148) at
android.app.ActivityThread.main(ActivityThread.java:5441) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628) Caused
by: android.view.InflateException: Binary XML file line #76: Binary
XML file line #76: Error inflating class
android.support.design.widget.FloatingActionButton at
android.view.LayoutInflater.inflate(LayoutInflater.java:543) at
android.view.LayoutInflater.inflate(LayoutInflater.java:427) at
android.view.LayoutInflater.inflate(LayoutInflater.java:374) at
android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at
android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.cyanlabsid.cetakphoto.PhotoPicker.onCreate(PhotoPicker.java:74)
at android.app.Activity.performCreate(Activity.java:6303) at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2376)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2483)
at android.app.ActivityThread.access$900(ActivityThread.java:153) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349)
at android.os.Handler.dispatchMessage(Handler.java:102) at
android.os.Looper.loop(Looper.java:148) at
android.app.ActivityThread.main(ActivityThread.java:5441) at
java.lang.reflect.Method.invoke(Native Method) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
Can somebody tell my fault?
Use
app:backgroundTint
in stead of
android:backgroundTint
Hope it will work.
Because android:backgroundTint doesn't work below android API 21, so you need to use app:backgroundTint instead.
Tried your code, the problem is with the 23.4.0 library.
Upgrade to 24.+ , there's no error in that lib.
For example :
implementation 'com.android.support:appcompat-v7:24.2.1' // appcompat library
implementation 'com.android.support:design:24.2.1'
You need to change the compile version to 24 too.
compileSdkVersion 24
Below API level 21 app versions not support for the
app:backgroundTint="#color/green"
or you can use this library for achieve more material design widgets.
https://github.com/navasmdc/MaterialDesignLibrary
happy coding...
You need to add
android:theme="#style/Theme.AppCompat"
in the XML_Layout file in which you are using FloatingActionButton...
I had the same problem
I faced the same issue with Pre-Lolipop version and to resolve it, I just changed "android:src" to "app:srcCompat" & it worked for me.
To make compatibility with older version and if you're using a Vector graphics (as drawable assets) you should use:
app:srcCompat="#drawable/you_graphics"
instead of:
android:src="#drawable/your_graphics"
I am using:
classpath 'com.android.tools.build:gradle:3.3.2'
and
distributionUrl=https://services.gradle.org/distributions/gradle-4.10.1-all.zip
I changed my XML to:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:focusable="true"
app:srcCompat="#drawable/mapit"
app:layout_anchor="#id/foundit_imageView"
app:layout_anchorGravity="bottom|right|end" />
and everything built and ran correctly.
I hope this helps
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#drawable/ic_add_foreground"
android:layout_margin="16dp" />
Use this
<com.google.android.material.floatingactionbutton.FloatingActionButton>
instead of
<android.support.design.widget.FloatingActionButton>
Make sure the library from which you declared the FloatingActionButton in the activity is the same as the one used for the layout markup
For example have
import com.google.android.material.floatingactionbutton.FloatingActionButton; in the activity and
com.google.android.material.floatingactionbutton.FloatingActionButton as the tag for the layout
I was using Material Design for my ExtendedFloatingActionButton and when using API 24 it would crash the app.
I tried updating my gradle dependencies to the latest version:
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0-alpha02'
but I had no luck with that either. My solution was adding android:theme="" even though I had set a style it would still crash so I set the theme to the same as the style and it worked perfectly.
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="#+id/btn_one"
android:theme="#style/"
style="#style/"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/text"
android:text="#string/text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Add in
build.gradle(:app)
implementation 'com.google.android.material:material:1.2.0'
Use this in your XML
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/icon_right"
app:backgroundTint="#color/green"
android:onClick="previewphoto"
app:layout_anchorGravity="bottom|right|end" />
use this code it will be work better ;
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
app:backgroundTint="#f9fcfc"
android:src="#drawable/chat_float"
tools:targetApi="lollipop" />
Related
I just migrated my project to androidx and i am getting an inflation error for inflating viewpager component...I replaced android.support.v4.view.ViewPager with androidx.viewpager.widget.ViewPager
This my xml file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:padding="#dimen/_1dp"
android:layout_height="wrap_content"
android:background="#color/banner_border_color">
<androidx.viewpager.widget.ViewPager
android:id="#+id/vp_slider"
android:layout_width="match_parent"
android:layout_height="#dimen/_140dp"
android:background="#drawable/thumb_new_background" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom">
<TextView
android:id="#+id/tv_banner_view_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="#dimen/_16dp"
android:background="#drawable/drawable_btn_curved"
android:paddingBottom="#dimen/_6dp"
android:paddingLeft="#dimen/_8dp"
android:paddingRight="#dimen/_8dp"
android:paddingTop="#dimen/_6dp"
android:visibility="gone"
android:text="#string/text_view_more"
android:textColor="#color/c_white"
android:textSize="#dimen/_8sp" />
</RelativeLayout>
</FrameLayout>
The Error i'm getting :
Caused by: android.view.InflateException: Binary XML file line #329: Binary XML file line #8: Error inflating class androidx.core.view.ViewPager
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class androidx.core.view.ViewPager
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.view.ViewPager" on path: DexPathList[
I figure out problem,
When we merger to androidx then android studio convert viewpager, swipe to refresh layout and some other views to androidx.core for example viewpager its looks like androidx.core.view.ViewPager but correct is androidx.viewpager.widget.ViewPager please check in your xml layouts and see there is right component is added or not if there is androidx.core then check for right one and replace it.
And also import dependency
implementation 'com.google.android.material:material:1.1.0-alpha08
You need to below dependencies in your build.gradle file
implementation 'com.google.android.material:material:1.1.0
You need to add below dependencies in your build.gradle file
implementation 'com.google.android.material:material:1.4.0
I think you need to Invalidate caches and restart
Go to File > Invalidate caches/Restart > ** Invalidate
Then rebuild project
I've searched for an answer to my problem, as shown in the title of this question, and found Error inflating class androidx.constraintlayout.ConstraintLayout after migration to androidx, which aligns with the official migration instructions presented in Migrating to AndroidX. I took the information as requiring me to change android.support.constraint.ConstraintLayoutto androidx.constraintlayout.widget.ConstraintLayout, but this doesn't work for me.
I haven't found anything about what dependency to put in my gradle file, so I tried this (this is a shot in the dark):
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
which is accepted but when I tried:
implementation 'androidx.constraintlayout.widget:constraintlayout:1.1.3'
I get ERROR: Failed to resolve: androidx.constraintlayout.widget:constraintlayout:1.1.3, so I used the previous implementation directive.
Here is my XML file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.jbiss.petminder.activities.MainActivity">
<!--<android.support.v7.widget.Toolbar-->
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/my_toolbar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#color/colorPrimaryDark"
android:elevation="4dp"
app:layout_constraintTop_toTopOf="parent"
app:popupTheme="#style/AppTheme.PopupOverlay"/>
<TextView
android:id="#+id/tvMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:accessibilityLiveRegion="assertive"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"
tools:text="error message goes here"/>
<TextView
android:id="#+id/tvEmVet"
android:layout_width="wrap_content"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="20dp"
android:layout_marginTop="8dp"
android:text="#string/emergency_vet"
android:textColor="#android:color/holo_red_dark"
android:textSize="24sp"
app:layout_constraintStart_toEndOf="#+id/phoneCallEmVet"
app:layout_constraintTop_toBottomOf="#+id/recyclerview1"
tools:textSize="24sp"/>
<ImageView
android:id="#+id/phoneCallEmVet"
android:layout_width="37dp"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="8dp"
android:onClick="callEmVet"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/recyclerview1"
app:srcCompat="#android:drawable/sym_action_call"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview1"
android:layout_width="368dp"
android:layout_height="365dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/pet_name"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/my_toolbar"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Running my app produces the following error:
2019-02-18 19:43:36.031 458-458/com.example.jbiss.petminder E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.jbiss.petminder, PID: 458
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.jbiss.petminder-i-ubC_oLu_y7-aFpiqALqg==/base.apk", zip file "/data/app/com.example.jbiss
Following the information doesn't work, for some reason. The migration has been tough but I've cleaned up a lot of issues and am now unable to find a reason why this is happening when it appears that I have done what is intended.
I solved my problem. I found that Androidx migration is a bit more involved than I had at first thought. Knowing that I had updated the labels of the ConstraintLayout elements in the XML files used in the initial screen, I used Windows GREP to search for "android.support.constraint.ConstraintLayout" throughout my project. Lo and behold I found instances that I had missed and so I updated the XML file reference to "androidx.constraintlayout.widget.ConstraintLayout".
This allowed my project to be successfully built and launch on the emulator. However, after trying to access another screen I got the same error as shown in my initial post, but for the AppBarLayout. So, I must proceed for this one as I did for ConstraintLayout and then any others.
If you are migrating, be prepared for a little more work than you had anticipated!
I was facing the same problem after migrating to androidX. Tried above solution. But, it didn't work. I added mavenCentral() in project level app gradle.
repositories {
jcenter()
maven { url 'https://maven.google.com' }
mavenCentral()
}
with following changes
dependencies {
implementation 'com.google.android.material:material:1.0.0'
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}
updated "android.support.constraint.ConstraintLayout" xml tag with "androidx.constraintlayout.widget.ConstraintLayout"
finally it worked.
If you experience this issue on Android Studio 3.6.3 after using the Migrate to Androidx tool like I did, Here is what worked for me:
I was using androidx.constraintlayout.ConstraintLayout in my layout XML file instead of androidx.constraintlayout.widget.ConstraintLayout
The difference is one has widget before ConstraintLayout. The dependency in my app-level build.gradle was:
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
The latest at that time.
I am trying to implement SwipeRefreshLayout in fragments. It is looking created correctly, but I continue to get the errors:
Caused by: android.view.InflateException: Binary XML file line #2:
Binary XML file line #2: Error inflating class
android.support.v4.widget.SwipeRefreshLayout
Caused by: android.view.InflateException: Binary XML file line #2:
Error inflating class android.support.v4.widget.SwipeRefreshLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class
"android.support.v4.widget.SwipeRefreshLayout" on path:
DexPathList[[zip file "/data/app/com.weather.rainy-
2/base.apk"],nativeLibraryDirectories=[/data/app/com.weather.rainy-
2/lib/x86, /system/lib, /vendor/lib]]
I really don't have any idea what is causing this.
My fragment layout for implementing the SwipeRefreshLayout:
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/swipeToRefresh4Maps"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/topRL4Maps"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg_gradient_purple"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingTop="64dp"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingBottom="64dp"
tools:context="com.weather.rainy.ui.MapsActivity">
<TextView
android:id="#+id/yourLocationLabelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="#+string/your_location"
android:textColor="#android:color/white"
android:textSize="24sp" />
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/addressValueTextView"
android:layout_alignBottom="#+id/addressValueTextView"
android:layout_below="#+id/yourLocationLabelTextView"
android:layout_centerHorizontal="true"
android:layout_margin="15dp"
tools:context="com.weather.rainy.ui.MapsActivity" />
<TextView
android:id="#+id/addressValueTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/map"
android:layout_alignEnd="#+id/map"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="true"
android:text="#+string/..."
android:textColor="#aaffffff"
android:textSize="18sp" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
And, my fragment class for calling the SwipeRefreshLayout:
//Code for Swipe Refresh
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh4Maps);
mSwipeRefreshLayout.setColorSchemeResources(R.color.Red, R.color.Orange, R.color.Blue, R.color.Green);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
Log.v(TAG, "************** MAPS - SWIPE REFRESH EVENT TRIGGERED!!!!!");
findLocation();
}
});
I really don't have any clue, what is the wrong. Any help is greatly appreciated.
Because you are using AndroidX, your XML is referencing the wrong version of SwipeRefreshLayout
Change in your XML from android.support.v4.widget.SwipeRefreshLayout to androidx.swiperefreshlayout.widget.SwipeRefreshLayout
I was stuck on the SwipeRefreshLayout using AndroidX
I was not able to get Reference of SwipeRefreshLayout in AndroidX
So I added implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
dependency in app level gradle file.
So in my case solution is,
Add the dependency in app level build.gradle file
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
This issue seems to happen when migrating to AndroidX as there are many build artifact to be changed when Migrating to AndroidX.
Solution 1: Do it manually
For exemple:
android.support.v4.widget.SwipeRefreshLayout changed to => androidx.swiperefreshlayout.widget.SwipeRefreshLayout
You must update all the build artifact listed in Migrating to AndroidX
Solution 2: Automate on Android Studio 3.2+
As suggested in this same link, you could automate this process by selecting Refactor > Migrate to AndroidX from the menu bar.
ADDITIONAL INFO - The errors I had:
Error inflating class android.support.constraint.ConstraintLayout
element WebView is not allowed here
Gradle needs to new dependency which is AndroidX:
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
If you use SwipeRefreshLayout in Java class, you can see this line:
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
In you XML file, you should use the tags of SwipeRefreshLayout:
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
This happened a couple of days ago. Still cannot find the way to fix it.
Here is a simple test project.
http://s000.tinyupload.com/index.php?file_id=03903482111052488979
Pretty simple layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<EditText
android:id="#+id/editUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="#string/input_hint_email"
android:inputType="textEmailAddress"
/>
<EditText
android:id="#+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="#string/edit_hint_password"
android:inputType="textPassword"
android:layout_gravity="center"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Enter"
/>
</LinearLayout>
Gradle important parts:
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.2.1'
}
Ple-lollipop devices (genymotion and real devices)
The background (pressed, sometimes normal) looks like something wrong with 9-patch file. Some of affected views - item in navigation view, menu item, edittext
edittext - https://gyazo.com/71f13003a46ff596514e475a72f924b7
pressed menu item - https://gyazo.com/7a5d9db29e17524e353f10a18562786e
Lollipop until 5.1
Crashes on startup (stop crashing on appcompat 23.1.1 and lower)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ww.aeli.wtf.MainActivity}: android.view.InflateException:
Binary XML file line #11: Error inflating class EditText
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class EditText at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v21/abc_edit_text_material.xml from drawable resource ID #0x7f020015 at android.content.res.Resources.loadDrawableForCookie(Resources.java:2428)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #24: <nine-patch> requires a valid 9-patch source image at android.graphics.drawable.NinePatchDrawable.updateStateFromTypedArray(NinePatchDrawable.java:445)
Lollipop 5.1 and marshmallow
Everything works fine
What have i tried
Problem also was reproduced on other developer machine.
Downgrading appcompat till the version 23.0.0. Lollipop do not crashes on 23.1.1 and lower, but background problem persists.
Disabling vector support (the main 23.2.0 feature, that theoretically could affect).
Similar recent problems - https://code.google.com/p/android/issues/detail?id=210467 (the discussion went on the strange way), https://github.com/afollestad/material-dialogs/issues/1081, https://code.google.com/p/android/issues/detail?id=210547
older one:
https://code.google.com/p/android/issues/detail?id=198457
Well, i find the way to "fix" all the issues as always just after posting a question.
Downgrading the gradle version from 2.2.0-alpha1 to 2.1.+ will solve all the problems.
And again note to myself - never use "+" in library versions.
I am getting a bug using the official FloatingActionButton from Google's support design library.
Here is my LogCat.
android.view.InflateException: Binary XML file line #34: Error inflating class android.support.design.widget.FloatingActionButton
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:655)
at android.view.LayoutInflater.inflate(Unknown Source)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at ---.---.com.---.SubCategoryFragment.onCreateView(SubCategoryFragment.java:47)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:458)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
... 24 more
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable()' on a null object reference
at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:968)
at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1014)
at android.graphics.drawable.RippleDrawable$RippleState.<init>(RippleDrawable.java:910)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:901)
at android.graphics.drawable.RippleDrawable.createConstantState(RippleDrawable.java:90)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:932)
at android.graphics.drawable.RippleDrawable.mutate(RippleDrawable.java:891)
at android.view.View.applyBackgroundTint(View.java:16324)
at android.view.View.setBackgroundDrawable(View.java:16193)
at android.support.design.widget.FloatingActionButton.access$201(FloatingActionButton.java:56)
at android.support.design.widget.FloatingActionButton$1.setBackgroundDrawable(FloatingActionButton.java:118)
at android.support.design.widget.FloatingActionButtonLollipop.setBackgroundDrawable(FloatingActionButtonLollipop.java:75)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:131)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:79)
... 27 more
The only line that points to my app is where it inflates the xml file, and the line in that file which is my FloatingActionButton.
<android.support.design.widget.FloatingActionButton
android:id="#+id/myFABSubCat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="16dp"
android:backgroundTint="#color/accent"
android:src="#drawable/add_icon"
app:borderWidth="0dp"
app:elevation="4sp" />
Extra info:
Here is my app theme:
<resources>
<!-- Base application theme. -->
<style name="MBTIAppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primaryDark</item>
<item name="colorAccent">#color/accent</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="ThemeNoActionBar" parent="MBTIAppTheme">
<item name="windowActionBar">false</item>
</style>
</resources>
Yes, I am using an AppCompatActivity.
I noticed I am using an older version of appcompat:
com.android.support:appcompat-v7:22.1.1
This seems to be up to date:
compile 'com.android.support:design:22.2.0'
Also,
minSdkVersion 16
targetSdkVersion 22
Now, I do set the Visibility to GONE in some case for my FAB, but this is after it inflates so that can't be the issue.
Now, this works with my 5.1 device, but the users who have issues have 5.0.
Is this a known bug or maybe I am doing something wrong?
com.android.support:appcompat-v7:21+ added support for tinting widgets on devices running pre android 5.1 (API Level 21). To make use of it make sure you extend or set the AppCompat Theme and use app:backgroundTint instead of android:backgroundTint.
Example:
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="#drawable/icon"
app:backgroundTint="#color/accent"
app:borderWidth="0dp" />
Just replace
<android.support.design.widget.FloatingActionButton
...
...
android:backgroundTint
/>
to
<android.support.design.widget.FloatingActionButton
...
...
app:backgroundTint
/>
If you're using a VectorDrawableCompat (Vector asset) you should use:
app:srcCompat="#drawable/x"
instead of:
android:src="#drawable/x"
I had the same issue and tried different solution. But the one that worked for me was to ensure that appcompat and design support library versions are the same.
for example:
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
Just change android to app:
android:backgroundTint="#color/accent"
To:
app:backgroundTint="#color/accent"
Another way to get this message is if you accidentally specified different versions of the appcompat library in different modules. This is likely to happen when you create a new module, since Android Studio defaults to the most current version.
For a tidy way of managing this in multi-module projects, see: In Gradle, how do I declare common dependencies in a single place?
in my case, it was because of the false configuration of activity theme. problem was solved after i changed app theme to Theme.AppCompat.xxx.