Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InflateException with 0.1.7 using AboutFragment #69

Closed
hameno opened this issue Jun 27, 2020 · 7 comments
Closed

InflateException with 0.1.7 using AboutFragment #69

hameno opened this issue Jun 27, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@hameno
Copy link

hameno commented Jun 27, 2020

After updating from 0.1.6 I'm getting the following error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: de.psdev.devdrawer.debug, PID: 13426
    android.view.InflateException: Binary XML file line #2 in de.psdev.devdrawer.debug:layout/attribouter_item_app_info: Binary XML file line #2 in de.psdev.devdrawer.debug:layout/attribouter_item_app_info: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #2 in de.psdev.devdrawer.debug:layout/attribouter_item_app_info: Error inflating class <unknown>
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:854)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:659)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at me.jfenn.attribouter.adapters.WedgeAdapter.onCreateViewHolder(WedgeAdapter.kt:12)
        at me.jfenn.attribouter.adapters.WedgeAdapter.onCreateViewHolder(WedgeAdapter.kt:8)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7216)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6347)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6231)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6227)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2330)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1631)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:668)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4230)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3941)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4499)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1695)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
        at android.view.View.layout(View.java:21912)
E/AndroidRuntime:     at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:270)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:779)
        at android.view.View.layout(View.java:21912)
        at android.view.ViewGroup.layout(ViewGroup.java:6260)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3080)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2590)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1721)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7598)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:966)
        at android.view.Choreographer.doCallbacks(Choreographer.java:790)
        at android.view.Choreographer.doFrame(Choreographer.java:725)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:951)
        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)
     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 2: TypedValue{t=0x2/d=0x7f04003a a=-1}
        at android.content.res.TypedArray.getColorStateList(TypedArray.java:596)
        at androidx.cardview.widget.CardView.<init>(CardView.java:127)
        at com.google.android.material.card.MaterialCardView.<init>(MaterialCardView.java:117)
        at com.google.android.material.card.MaterialCardView.<init>(MaterialCardView.java:113)
        	... 71 more

Usage is like this (in another fragment):

if (childFragmentManager.findFragmentById(R.id.container_fragment) == null) {
    childFragmentManager.commit {
        add(R.id.container_fragment, Attribouter.from(requireContext()).toFragment())
    }
}
@fennifith fennifith added the bug Something isn't working label Jun 27, 2020
@fennifith
Copy link
Owner

Yep, I can reproduce this - I failed to actually test the fragment functionality before releasing :P

I have a hunch that this is caused by missing theme attrs - #62 could potentially resolve this by using a default theme in the fragment instead of inheriting the activity's.

@fennifith
Copy link
Owner

Alright, 0.1.8 should solve your problem - hopefully this is fixed now! Let me know if you have any other problems :)

@hameno
Copy link
Author

hameno commented Jun 28, 2020

Yes, fixed now. But I noticed something else: attribouterFragment is scoped to ContextWrapper - any specific reason why? I think Context should be enough

@fennifith
Copy link
Owner

Evidently not, or this bug wouldn't have occurred. The ContextWrapper allows the fragment to inflate layouts with their own theme attrs, e.g. ?attr/attribouter_textColorAccent, without making it a requirement that the containing Activity also implement them. (it's necessary that these be present in a style resource so that its values changed easily, e.g. in a -night configuration, or from an app's own "theme" setting)

If you wish to change this, you can use withTheme(...) to pass your own style instead - but if it doesn't implement the same attributes as AttribouterTheme, it will cause a similar crash to this.

@hameno
Copy link
Author

hameno commented Jun 28, 2020

But for the fragment use case you are not actually using the provided Context instance anywhere from what I can see in the Attribouter class. It is only used for the activity to start the activity.

@fennifith
Copy link
Owner

fennifith commented Jun 28, 2020

Oh, are you talking about the extension functions used to configure it? Yes, those could be rewritten; it ultimately has little impact on the usage, though. If you wanted to, you could just construct Attribouter(context) instead.

I'm not sure why ContextWrapper was used - I probably just chose an arbitrary superclass of Activity, but you're right that it doesn't make a ton of sense in retrospect. I'll change that in a future version.

@hameno
Copy link
Author

hameno commented Jun 28, 2020

Yes, was talking about the extension functions. I'm currently using the Attribouter(context) because of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants