I have a problem regarding android layout that I am not able to resolve. I have a fragment with a layout that contains lots of elements and in particular this CardView element
<androidx.cardview.widget.CardView
android:id="#+id/search_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
app:cardBackgroundColor="#color/chartMax"
app:cardCornerRadius="20dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:text="Cerca"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="23sp" />
</androidx.cardview.widget.CardView>
I access this element in fragment
private lateinit var searchButton: CardView
searchButton = view.search_button
and everything works fine, I can use it normally.
The problems start when I add a normal SearchView to the fragment.
<androidx.appcompat.widget.SearchView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
When I run the application it crash on this instruction
searchButton = view.search_button
This is the stacktrace
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.atoka.mobile, PID: 31291
java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageView cannot be cast to androidx.cardview.widget.CardView
at io.atoka.mobile.fragments.SearchFragment.getViewElements(SearchFragment.kt:57)
at io.atoka.mobile.fragments.SearchFragment.onCreateView(SearchFragment.kt:73)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1391)
at android.app.Activity.performStart(Activity.java:7157)
at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2937)
at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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)
like if my CardView was an AppCompatImageView that is not. When I remove the SearchView the application works normally.
Anyone knows the solution? Is there any bug regarding this particular case?
Thank you
Your problem occurs because of the name you gave to your cardview
search_button is already define in default androidx.appcompat.widget.SearchView class as below:
final ImageView mSearchButton;
mSearchButton = findViewById(R.id.search_button);
so when you trying to get it from binding it's getting conflicted with the SearchView class search_button parameter
try to change the name of your cardview to something else then try,
Related
The Fragments crashes when trying to get the data using the location with the error below:
2022-05-26 00:42:46.057 30678-30678/com.example.android.politicalpreparedness E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.politicalpreparedness, PID: 30678
java.lang.IndexOutOfBoundsException: setSpan (5 ... 5) ends beyond length 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1325)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:684)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:676)
at android.text.Selection.setSelection(Selection.java:96)
at android.text.Selection.setSelection(Selection.java:78)
at android.widget.EditText.setSelection(EditText.java:129)
at com.example.android.politicalpreparedness.representative.RepresentativeFragment$populateStatesInformation$1.onChanged(RepresentativeFragment.kt:119)
at com.example.android.politicalpreparedness.representative.RepresentativeFragment$populateStatesInformation$1.onChanged(RepresentativeFragment.kt:23)
at androidx.lifecycle.LiveData.considerNotify(LiveData.java:131)
at androidx.lifecycle.LiveData.dispatchingValue(LiveData.java:149)
at androidx.lifecycle.LiveData.setValue(LiveData.java:307)
at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)
at androidx.lifecycle.LiveData$1.run(LiveData.java:91)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I am confused how this is causing an error. It's supposed to show the value that's in the adapter right?
Fragment Code :
private fun populateStatesInformation() {
val statesArray = requireContext().resources.getStringArray(R.array.states)
binding.addressState.setAdapter(ArrayAdapter(requireContext(), R.layout.layout_state_list_item, statesArray))
viewModel.address.observe(viewLifecycleOwner) {
var index = statesArray.indexOf(it.state)
if (index == -1) {
index = 0
}
binding.addressState.setSelection(index)
}
}
The XML Code for that text field.
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/address_state_layout"
style="#style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:hint="#string/address_state"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/address_zip_layout"
app:layout_constraintTop_toTopOf="#id/address_zip_layout">
<AutoCompleteTextView
android:id="#+id/address_state"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:editable="false"
android:ellipsize="end"
android:maxLines="1"
tools:ignore="Deprecated,LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
This error is because setSelection(i) doesn't select item i from the adapter for a AutoCompleteTextView, it attempts to move the cursor to position i in the current text, so if i is greater than the length of the text you get that error.
You can use setSelection(i) with a Spinner, but it has different behavior with an AutoCompleteTextView. To do the equivalent of setSelection in a AutoCompleteTextView, use this instead of the setSelection call:
binding.addressState.setText(statesArray[index], false)
The second argument (false) is necessary for it to operate like a spinner and keep the options around instead of applying a filter.
There is an older, but still useful, thread about this issue here too.
View Binding got released with v3.6.
https://developer.android.com/topic/libraries/view-binding
I am going to use view binding with included layouts.
So I refer to the following answer that is useful.
How to use View Binding with Included Views?
But it doesn't work well.
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
mainBinding.myHeader.foo.setText("this is a test");
}
}
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/my_header"
layout="#layout/item_header"
android:layout_width="match_parent"
android:layout_height="100dp" />
</LinearLayout>
However, the following error occurs.
2020-04-21 10:18:25.135 30977-30977/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 16941
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang.NullPointerException: Missing required view with ID: itemId
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Missing required view with ID: itemId
at com.example.myapplication.databinding.ItemHeaderBinding.bind(ItemHeaderBinding.java:73)
at com.example.myapplication.databinding.ActivityMainBinding.bind(ActivityMainBinding.java:60)
at com.example.myapplication.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:46)
at com.example.myapplication.databinding.ActivityMainBinding.inflate(ActivityMainBinding.java:36)
at com.example.myapplication.MainActivity.onCreate(MainActivity.java:13)
at android.app.Activity.performCreate(Activity.java:7825)
at android.app.Activity.performCreate(Activity.java:7814)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
What's wrong?
If I remove id of include layout, there are other errors.
I have resolved the problem.
Original item_header.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/item_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:background="#android:color/transparent">
<TextView
android:id="#+id/foo"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
I removed id of framelayout and the error was soon gone.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:background="#android:color/transparent">
<TextView
android:id="#+id/foo"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
Be careful about using id while using view binding.
This is how I handled included layouts with view binding.
// When view binding is enabled it will create a binding class for each layout, converting the file name to Pascal case.
ActivityMainBinding binding;
IncludedLayout bindingIncludedLayout;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Inflate the layout as per google doc instructions
binding = ActivityMainBinding.inflate(getLayoutInflater());
// add the inflated view to the Included view.
bindingIncludedLayout = binding;
setContentView(binding.getRoot());
// binding in the main layout
binding.myView.setText("text");
// binding in the included layout
bindingIncludedLayout.textview_name.("additional text")
}
I would strongly recommend learning data binding over view binding, as data binding has a lot more potential, its like view binding on steroids.
This was the best tutorial I came across for learning data binding.
https://www.androidhive.info/android-working-with-databinding/
Its a few years old now but still very helpful in getting you started.
I have a TextInputEditText inside a TextInputLayout in my xml code.
<android.support.design.widget.TextInputLayout
android:id="#+id/textfieldContainer2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true"
app:errorTextAppearance="#style/customErrorTextColor"
app:hintTextAppearance="#style/customHintTextAppearance"
app:layout_constraintTop_toBottomOf="#id/textfieldContainer">
<android.support.design.widget.TextInputEditText
android:id="#+id/bottomtextfield"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="add bottom text"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</android.support.design.widget.TextInputLayout>
Problem
I am trying to get TextInputLayout via TextInputEditText as shown below
TextInputLayout parentInputLayout = (TextInputLayout) textfield.getParent();
but this line of code throws java.lang.IllegalStateException
Question
What am I doing wrong here and how can I get parent TextInputLayout of any TextInputEditText through TextInputEditText's reference.
Stacktrace
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.yousafkhan.memegeneratorapp, PID: 10425
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:390)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
at android.view.View.performClick(View.java:6597)
at android.view.View.performClickInternal(View.java:6574)
at android.view.View.access$3100(View.java:778)
at android.view.View$PerformClick.run(View.java:25885)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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: java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to android.support.design.widget.TextInputLayout
at com.example.yousafkhan.memegeneratorapp.MainActivity.textFieldEmpty(MainActivity.java:64)
at com.example.yousafkhan.memegeneratorapp.MainActivity.createMeme(MainActivity.java:53)
Getting a reference to the TextInputLayout that contains the TextInputEditText can be done as the following:
TextInputEditText textfield = findViewById(R.id.bottomtextfield);
ViewGroup containingLayout = (ViewGroup) textfield.getParent();
TextInputLayout textInputLayout = (TextInputLayout) containingLayout.getParent();
This is because TextInputLayout has a FrameLayout on it that contains the TextInputEditText associated.
The view hierarchy in xml may not be same as the view herarchy returned by android. So getParent() may not return you the expected view.
Therefore you should prefer using :
TextInputLayout parentInputLayout = findViewById(R.id.textfieldContainer2);
I have the following TextView
<TextView
android:id="#+id/LoginlinkLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical center_horizontal"
android:autoSizeMaxTextSize="45sp"
android:autoSizeMinTextSize="15sp"
android:autoSizeStepGranularity="2sp"
android:text="#string/Loginlink"
android:textAlignment="center"
android:textSize="15sp"
android:onClick="loginlinkLabelonClick"
android:clickable="true"/>
And this function
fun loginlinkLabelonClick(context:Context)
{
val urlString="http://www.google.gr"
val intent = Intent(Intent.ACTION_VIEW,Uri.parse(urlString)) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.`package`="com.android.chrome"
try
{
context.startActivity(intent)
}
catch(ex:ActivityNotFoundException)
{
intent.`package`= null
context.startActivity(intent)
}
}
The error message:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.reviewer.reviewer, PID: 27809
java.lang.IllegalStateException: Could not find method loginlinkLabelonClick(View) in a parent or ancestor Context for
android:onClick attribute defined on view class
android.support.v7.widget.AppCompatTextView with id 'LoginlinkLabel'
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.resolveMethod(AppCompatViewInflater.java:423)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:380)
at android.view.View.performClick(View.java:6291)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
But as soon as I tap the textview the application crashes and I can't seem to find what's wrong.
I'm new to Java, kotlin and Android studio.
I had a previous experience with visual studio and c# and Java / kotlin feels a bit strange
Now I'm really trying to figure out how to open urls, but I'm having trouble getting it to work
Usually when you have a click method in the xml, the argument for the method in kotlin is a view instance, see more here. So your method should look like this:
fun loginlinkLabelonClick(view:View)
{
}
Error: Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state.
I suddenly noticed this error today, and I'm not sure if it was because I just updated my testing device to Android 8.0. The error message clearly states there's something wrong with setting the ripple effect on the floating action button, and indeed there is no ripple effect when the button is pressed. However, I'm not sure what is causing this problem. Actually, the exact same bug is thrown twice in a row. Any help would be much appreciated! The rest of the app still runs normally, but the bug is really bothering me.
p.s. minSdkVersion is 22, targetSdkVersion and compiledSdkVersion are 27
In MyActivity, line 117 is the data binding and setting the content view.
ActivityMyBinding binding = DataBindingUtil.setContentView(
this, R.layout.activity_my);
Here is the full stacktrace:
W/LayerDrawable: Invalid drawable added to LayerDrawable! Drawable already belongs to another owner but does not expose a constant state.
java.lang.RuntimeException
at android.graphics.drawable.LayerDrawable$ChildDrawable.<init>(LayerDrawable.java:1855)
at android.graphics.drawable.LayerDrawable$LayerState.<init>(LayerDrawable.java:1975)
at android.graphics.drawable.LayerDrawable.createConstantState(LayerDrawable.java:168)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1779)
at android.graphics.drawable.LayerDrawable.mutate(LayerDrawable.java:1785)
at android.graphics.drawable.RippleDrawable.mutate(RippleDrawable.java:997)
at android.view.View.applyBackgroundTint(View.java:21809)
at android.view.View.setBackgroundDrawable(View.java:21680)
at android.support.design.widget.FloatingActionButton.access$001(FloatingActionButton.java:68)
at android.support.design.widget.FloatingActionButton$ShadowDelegateImpl.setBackgroundDrawable(FloatingActionButton.java:824)
at android.support.design.widget.FloatingActionButtonLollipop.setBackgroundDrawable(FloatingActionButtonLollipop.java:73)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:179)
at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:151)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
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 android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:276)
at android.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:261)
at com.generica.genericb.genericc.MyActivity.onCreate(MyActivity.java:117)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2908)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3030)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6938)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
I needed to use app:backgroundTint instead of android:backgroundTint
Changing app:srcCompat="#android:drawable/..." to android:src="#android:drawable/..." fixed it for me.
Strange... whoever posted an answer before pointed me to the solution, but they deleted their answer. =/
They mentioned how a Drawable has a state, and if you assign it to more than one Floating Action Button, then there will be a problem keeping track of the Drawable's state. Apparently with a recent update, this problem was fixed. This led me to realize that I was setting the FAB's source with app:srcCompat rather than android:src.
if you have a Fab in the activity xml, keep the below code and delete android:backgroundTint="#color/colorPrimary"
This solved the issue.
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/list_fab_margin"
android:layout_marginTop="#dimen/list_fab_margin"
android:layout_marginEnd="#dimen/list_fab_margin"
android:layout_marginBottom="#dimen/list_fab_margin"
app:backgroundTint="#color/colorPrimary"
app:fabSize="mini"
app:srcCompat="#drawable/ic_edit"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="41dp"
tools:layout_editor_absoluteY="16dp" />