Reputation: 1144
I'm experiencing an odd behaviour regarding android.support.design.widget.FloatingActionButton
. I have googled around a little but found no mention of this kind of error for this component.
This only happens when I build with android StrictMode
enabled. I get the following exception:
CoordinatorLayout﹕ Default behavior class android.support.design.widget.FloatingActionButton$a could not be instantiated. Did you forget a default constructor?
java.lang.InstantiationException: can't instantiate class android.support.design.widget.FloatingActionButton$a; no empty constructor
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1130)
at android.support.design.widget.CoordinatorLayout.a(CoordinatorLayout.java:503)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:579)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16831)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:868)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16831)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5245)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2586)
at android.view.View.measure(View.java:16831)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2189)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1352)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1535)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
at android.view.Choreographer.doCallbacks(Choreographer.java:591)
at android.view.Choreographer.doFrame(Choreographer.java:561)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeN
This, however does not make my application to crash or throws any visible error. It's thrown each time the activity which has the FAB is created, but the FAB renders and works perfectly fine. If I click on it, it does what the onClickListener
says it should do.
This is are my Android Support Library dependencies, in my build.gradle
:
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
And this is how I use the FAB in my xml layout:
<android.support.design.widget.CoordinatorLayout
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/home_toolbar_wallet"
android:name="my.fragment.class"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
(...)
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/home_floating_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_18dp"
android:layout_margin="@dimen/action_button_margin"
app:borderWidth="0dp"
app:layout_anchor="@id/home_toolbar_wallet"
app:layout_anchorGravity="bottom|right|end"/>
In case you are wondering, this is how I enable StrictMode
:
StrictMode.ThreadPolicy.Builder builder = new StrictMode.ThreadPolicy.Builder builder = new StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog();
if (Utils.hasHoneycomb()) {
builder.penaltyFlashScreen();
}
StrictMode.setThreadPolicy(builder.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll()
.penaltyLog()
.build());
Anyone has encountered with this?
Upvotes: 0
Views: 791
Reputation: 11749
It could be due to proguard obfuscating your code. Have you tried to add this rule to your proguard rules?
-keepclassmembers class android.support.design.widget.FloatingActionButton$Behavior { public <init>(); }
Upvotes: 5