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

Error inflating class com.ncorti.slidetoact.SlideToActView #120

Open
2 of 3 tasks
agforte opened this issue May 26, 2020 · 7 comments
Open
2 of 3 tasks

Error inflating class com.ncorti.slidetoact.SlideToActView #120

agforte opened this issue May 26, 2020 · 7 comments

Comments

@agforte
Copy link

agforte commented May 26, 2020

What kind of issue is this?

  • UI Bug. Please provide a Screenshot/Video/GIF of what's the problem. If you need help to record a video you can follow this guide

  • Functional Bug. Please describe the scenario of the bug. Furthermore, please spend the time to write a failing test.

  • Feature Request. Start by telling what's problem you’re trying to solve. A Pull request is welcome as well.

Details

In Android Studio, in the XML preview, I can only see a placeholder where the slider should be. I have followed the instructions in the readme.

Screen Shot 2020-05-26 at 10 19 42 AM

When I try to run it on the device I get this error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xxxxx.xxx, PID: 1665
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxxx.xxx/com.xxxxx.xxx.MyActivity}: android.view.InflateException: Binary XML file line #91: Binary XML file line #21: Error inflating class com.ncorti.slidetoact.SlideToActView

and below also this

     Caused by: android.view.InflateException: Binary XML file line #91: Binary XML file line #21: Error inflating class com.ncorti.slidetoact.SlideToActView
     Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class com.ncorti.slidetoact.SlideToActView
     Caused by: java.lang.reflect.InvocationTargetException
        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.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:995)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        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 com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:444)
        at android.app.Activity.setContentView(Activity.java:2659)
        at com.xxxxxx.xxxxx.MyActivity.onCreate(MyActivity.java:152)
        at android.app.Activity.performCreate(Activity.java:6980)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2811)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2933)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1612)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6710)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 7: TypedValue{t=0x2/d=0x7f0300a6 a=1236}
        at android.content.res.TypedArray.getColor(TypedArray.java:469)
        at com.ncorti.slidetoact.SlideToActView.<init>(SlideToActView.kt:293)
        at com.ncorti.slidetoact.SlideToActView.<init>(SlideToActView.kt:49)
        at com.ncorti.slidetoact.SlideToActView.<init>(Unknown Source:6)
        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.rInflate(LayoutInflater.java:866) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:995) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866) 
        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 com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:444) 
        at android.app.Activity.setContentView(Activity.java:2659) 
        at com.xxxxxx.xxxxx.MyActivity.onCreate(MyActivity.java:152) 
        at android.app.Activity.performCreate(Activity.java:6980) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2811) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2933) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1612) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6710) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770) 

In case of bug report, please don't forget to include also:

  • Library Version: 0.8.0
  • Android Version: Android 8
  • Emulator/Device specs: LG V20
  • Logs/Crash reports/Stacktraces: Min SDK 17, Target SDK 29
  • Example Code/Link to repositories.
@quanta-kt
Copy link
Contributor

quanta-kt commented May 26, 2020

This might not necessarily be a library bug but an error in your code (which seems more likely be the case).

Please attach your layout XML file which uses the SlideToActView, if possible with line numbers.

@agforte
Copy link
Author

agforte commented May 26, 2020

Now the XML preview in Android Studio magically shows the preview of the swipe button and not the placeholder as before. The crash is still there though.

Here is the XML:

01 <?xml version="1.0" encoding="utf-8"?>
02 <androidx.coordinatorlayout.widget.CoordinatorLayout
03   xmlns:android="http://schemas.android.com/apk/res/android"
04   xmlns:app="http://schemas.android.com/apk/res-auto"
05   xmlns:tools="http://schemas.android.com/tools"
06   android:id="@+id/l_body"
07   android:layout_width="match_parent"
08   android:layout_height="wrap_content"
09   android:layout_centerHorizontal="true"
10    android:layout_gravity="center"
11    android:visibility="visible"
12    tools:context="com.xxxxxx.xxxxx.MyActivity">
13
14    <LinearLayout
15        android:layout_width="match_parent"
16        android:layout_height="wrap_content"
17        android:orientation="vertical"
18        android:layout_gravity="center"
19        android:gravity="center">
20
21        <com.ncorti.slidetoact.SlideToActView
22            android:id="@+id/slider"
23            android:layout_width="match_parent"
24            android:layout_height="wrap_content"
25            app:text="Example"/>
26
27        <TextView
28            android:id="@+id/myId1"
29            android:layout_width="match_parent"
30            android:layout_height="wrap_content"
31            android:layout_gravity="center"
32            android:layout_marginTop="20dp"
33            android:layout_weight="1"
34            android:drawableTop="@drawable/home"
35            android:drawablePadding="7dp"
36            android:drawableTint="@color/liteIconColor"
37            android:fontFamily="sans-serif-medium"
38            android:gravity="center"
39            android:tag="@string/view_1"
40            android:text="@string/view_1"
41            android:textColor="@color/textColorLiter"
42            android:textSize="15sp"
43            android:typeface="sans" />
44
45        <TextView
46            android:id="@+id/myId2"
47            android:layout_width="match_parent"
48            android:layout_height="wrap_content"
49            android:layout_gravity="center"
50            android:layout_marginTop="20dp"
51            android:layout_marginBottom="46dp"
52            android:layout_weight="1"
53            android:drawableTop="@drawable/clock"
54            android:drawablePadding="7dp"
55            android:drawableTint="@color/liteIconColor"
56            android:fontFamily="sans-serif-medium"
57            android:gravity="center"
58            android:tag="@string/view_2"
59            android:text="@string/view_2"
60            android:textColor="@color/textColorLiter"
61            android:textSize="15sp"
62            android:typeface="sans" />
63
64    </LinearLayout>
65 </androidx.coordinatorlayout.widget.CoordinatorLayout>

@cortinico
Copy link
Owner

Now the XML preview in Android Studio magically shows the preview of the swipe button and not the placeholder as before.

The placeholder gets rendered correctly once you build the app and run it.

For the crash, are you using AndroidX or the old support library?

@agforte
Copy link
Author

agforte commented May 26, 2020

I am confused. Does you library have dependencies not documented in the README?

In the README it says to just add

dependencies {
   implementation "com.ncorti:slidetoact:0.8.0"
}

and that's it.

I am using AndroidX for other components as you can see in the layout code I posted above, but I have not added anything else (aside from the above) that is related to your library.
In particular, I am using:

'com.google.android.material:material:1.2.0-alpha06'

@cortinico
Copy link
Owner

I am confused. Does you library have dependencies not documented in the README?

The library internally has two dependencies: the Kotlin stdlib and androidx.appcompat. You anyway don't need to declare them as they will be imported automatically.

I am using AndroidX for other components as you can see in the layout code

Yeah you're right. So the crash seems to be related to the inflating of the outer_color attribute:

actualOuterColor = getColor(R.styleable.SlideToActView_outer_color, defaultOuter)

I can't find anything wrong with your layout. Ideally if you could share a project where the crash occur, it would be really beneficial to help debugging.

@agforte
Copy link
Author

agforte commented May 26, 2020

Unfortunately I do not have the time to create a project to share right now. However, I can confirm that the problem is with outer_color. I have set outer_color to a value and now it does not crash any longer.
If I do not set outer_color then by default it picks up colorAccent according to my theme. This is when the crash happens.

@cortinico cortinico added the bug label May 26, 2020
@cortinico
Copy link
Owner

If I do not set outer_color then by default it picks up colorAccent according to my theme. This is when the crash happens.

I assume you don't have colorAccent set in your theme, right?
Looks like this is a real bug. The widget fallbacks the outer_color property to the ?colorAccent theme attribute:

<item name="outer_color">?colorAccent</item>

If that is missing the consuming app seems to crash with the stacktrace you reported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants