1

I made a layout for my app and it works perfectly on Nougat and up, but for whatever reasons app crashes on Android 6.0 with following error:

05-01 18:26:02.658   805  1839 I ActivityManager: START u0 {cmp=com.vanced.manager/.ui.MainActivity} from uid 10081 on display 0
05-01 18:26:02.691 13123 13123 I art     : Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
05-01 18:26:02.692 13123 13123 I art     : Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
05-01 18:26:02.699   805  1623 D ConnectivityService: notifyType CAP_CHANGED for NetworkAgentInfo [WIFI () - 100]
05-01 18:26:02.825  9919  9987 I FontsContentProvider: Received query name=Exo&weight=600, URI content://com.google.android.gms.fonts
05-01 18:26:02.825  9919  9987 I FontsContentProvider: Query [name=Exo&weight=600] resolved to {Exo, wdth 100.0, wght 600, ital 0.0, bestEffort false}
05-01 18:26:02.829 13123 13123 D AndroidRuntime: Shutting down VM
05-01 18:26:02.833 13123 13123 E AndroidRuntime: FATAL EXCEPTION: main
05-01 18:26:02.833 13123 13123 E AndroidRuntime: Process: com.vanced.manager, PID: 13123
05-01 18:26:02.833 13123 13123 E AndroidRuntime: Theme: themes:{}
05-01 18:26:02.833 13123 13123 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vanced.manager/com.vanced.manager.ui.MainActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class TextView
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2450)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.app.ActivityThread.-wrap11(ActivityThread.java)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:102)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:148)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:5461)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-01 18:26:02.833 13123 13123 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class TextView
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at com.vanced.manager.ui.fragments.HomeFragment.onCreateView(HomeFragment.kt:32)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2224)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1997)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2629)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2577)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:2722)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:346)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1188)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2577)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:247)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:541)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1238)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.app.Activity.performStart(Activity.java:6268)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        ... 9 more
05-01 18:26:02.833 13123 13123 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class TextView
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.rInflate(LayoutInflater.java:838)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.rInflate(LayoutInflater.java:831)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
05-01 18:26:02.833 13123 13123 E AndroidRuntime:        at android.view.LayoutInflater.rInflate(L
05-01 18:26:02.839   805  2693 W ActivityManager:   Force finishing activity com.vanced.manager/.ui.MainActivity

Error happens in this layout:

<com.google.android.material.card.MaterialCardView
    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"
    app:cardCornerRadius="@dimen/eightdp"
    app:cardBackgroundColor="?colorSurfaceVariant"
    app:cardElevation="0dp"
    app:cardPreventCornerOverlap="true"
    app:contentPaddingRight="8dp"
    app:contentPaddingLeft="8dp"
    app:contentPaddingTop="5dp"
    app:contentPaddingBottom="5dp">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/vanced_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/ic_vanced"
            android:drawablePadding="8dp"
            android:fontFamily="@font/exo_bold"
            android:text="@string/vanced"
            android:textColor="?colorPrimary"
            android:textSize="24sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

and problem is with <TextView/> tag. I'm unsure why does this happen on Marshmallow and not on Nougat+ (haven't tested lollipop but I think problem occurs there too). Can anyone explain?

UPDATE: Here's HomeFragment.kt

package com.vanced.manager.ui.fragments
import android.content.Context
import android.net.ConnectivityManager
import android.net.Networkimport android.net.NetworkCapabilities
import android.net.NetworkRequestimport android.os.Bundle
import android.view.*import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.card.MaterialCardView
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.vanced.manager.R
import com.vanced.manager.adapter.SectionPageAdapter
import com.vanced.manager.core.fragments.Home 

class HomeFragment : Home() { 
    private lateinit var sectionPageAdapter: SectionPageAdapter
    private lateinit var viewPager: ViewPager2

    override fun onCreateView( 
        inflater: LayoutInflater, 
        container: ViewGroup?, 
        savedInstanceState: Bundle? ): 
    View? { 
        activity?.title = getString(R.string.title_home) 
        setHasOptionsMenu(true) return  
        inflater.inflate(R.layout.fragment_home, container, false) }
9
  • Binary XML file line #20 which in line no 20? Commented May 1, 2020 at 17:03
  • I included the layout xml code where the error happens. Commented May 1, 2020 at 17:05
  • i know. but what is line no 20 in xml? Commented May 1, 2020 at 17:05
  • Line 20 is where TextView tag starts Commented May 1, 2020 at 17:06
  • Commenting out didn't solve the problem, same error occurs Commented May 1, 2020 at 17:32

2 Answers 2

1

05-01 18:26:02.833 13123 13123 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class TextView

android:textColor="?colorPrimary" invoke <attr format="color" name="colorPrimary"/>. It will be good approach if you use

 android:textColor="@color/colorPrimary"  // call hex code from color xml

NOTE

Seems like your android:drawableStart="@drawable/ic_vanced" causing issue. Kindly remove and run.

Then Clean-Rebuild-Run.

Sign up to request clarification or add additional context in comments.

16 Comments

Thanks guys I'll try that
@Xinto remove app:cardBackgroundColor="?colorSurfaceVariant"
Using srcCompat doesn't display logo at all, I guess I'll have to move logo out of textview
Haha, yeah... I always hated pre android N version except KitKat, now I have even more reasons to do that xD
Don't think so because other vector drawables work just fine, checked gradle build file too and I did specify use of vector drawables
|
0

In the textview property

remove

 android:textColor="?colorPrimary"

Add

android:textColor="@color/colorPrimary"

2 Comments

Well, I have colorPrimary as attribute because I have 2 themes that need separate colors for colorPrimary and I want to change that text depending on theme, is that the only variant?
that case you should apply theme in the activity tag in the manifest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.