Двоичная XML строка файла # 20: Ошибка надувания класса TextView в Android 6.0 - PullRequest
1 голос
/ 01 мая 2020

Я сделал макет для своего приложения, и он отлично работает на Nougat и выше, но по тем или иным причинам приложение вылетает на Android 6.0 со следующей ошибкой:

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

В этом макете возникает ошибка:

<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" />

и проблема с тегом <TextView/>. Я не уверен, почему это происходит на Зефире, а не на Nougat + (не тестировал леденец, но я думаю, что проблема также возникает там). Кто-нибудь может объяснить?

ОБНОВЛЕНИЕ: Вот 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) }

Ответы [ 2 ]

1 голос
/ 01 мая 2020

05-01 18: 26: 02.833 13123 13123 E AndroidRuntime: вызвано: android .view.InflateException: двоичный файл XML строка файла # 20: ошибка надувания класса TextView

android: textColor = "? ColorPrimary" invoke <attr format="color" name="colorPrimary"/>. Это будет хороший подход, если вы используете

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

ПРИМЕЧАНИЕ

Похоже, что ваша android:drawableStart="@drawable/ic_vanced" вызывает проблему. Пожалуйста, удалите и запустите.

Затем Clean-Rebuild-Run.

0 голосов
/ 01 мая 2020

В свойстве textview

удалить

 android:textColor="?colorPrimary"

Добавить

android:textColor="@color/colorPrimary"
...