#android #android-layout #kotlin #inflate-exception
#Android #android-макет #котлин #надувать-исключение
Вопрос:
Я пробовал несколько решений, если я удалю код из строки 107
, чтобы 188
все работало нормально, и ошибки в инфляции нет, но я не могу точно определить ошибку в этом конкретном коде.
В Android 8 все работает нормально без удаления какого-либо кода, но когда я компилирую это в Android 6, он вылетает в строке 119.
Файл макета:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context="com.jutt.professoryapp.view.fragments.LoginFragment">
<ImageView
android:id="@ id/ivArabLogin"
android:layout_width="@dimen/margin_design_307"
android:layout_height="@dimen/margin_design_498"
android:layout_marginTop="@dimen/margin_design_162"
android:contentDescription="@string/app_name"
android:src="@drawable/arab_login_image"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/email_input_layout"
style="@style/AppTextInputLayoutOutlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_design_100"
android:hint="@string/email"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/ivArabLogin">
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLength="@integer/maxLength_email" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@ id/password_input_layout"
style="@style/AppTextInputLayoutOutlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_design_100"
android:layout_marginTop="@dimen/margin_design_36"
android:layout_marginEnd="@dimen/margin_design_100"
android:hint="@string/password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@ id/email_input_layout">
<com.google.android.material.textfield.TextInputEditText
android:id="@ id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@ id/btnLogin"
style="@style/AppButton.RoundCorners"
android:layout_width="0dp"
android:layout_height="@dimen/margin_design_140"
android:layout_marginTop="@dimen/margin_design_36"
android:text="@string/login"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
app:layout_constraintEnd_toEndOf="@ id/password_input_layout"
app:layout_constraintStart_toStartOf="@ id/password_input_layout"
app:layout_constraintTop_toBottomOf="@ id/password_input_layout" />
<com.google.android.material.button.MaterialButton
android:id="@ id/btnLoginAsGuest"
style="@style/AppButton.RoundCorners"
android:layout_width="0dp"
android:layout_height="@dimen/margin_design_140"
android:layout_marginTop="@dimen/margin_design_36"
android:text="@string/login_as_guest"
android:visibility="gone"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
app:layout_constraintEnd_toEndOf="@ id/btnLogin"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@ id/btnLogin"
app:layout_constraintTop_toBottomOf="@ id/btnLogin" />
<com.google.android.material.button.MaterialButton
android:id="@ id/mbtn_ForgetPassword"
style="@style/AppButton.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/forget_password_q"
app:layout_constraintStart_toStartOf="@ id/btnLogin"
app:layout_constraintTop_toBottomOf="@ id/btnLogin" />
<com.google.android.material.button.MaterialButton
android:id="@ id/mbtn_signup"
style="@style/AppButton.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@ id/btnLogin"
app:layout_constraintStart_toStartOf="@ id/btnLogin"
app:layout_constraintTop_toBottomOf="@ id/mbtn_ForgetPassword" />
//////// Buggy Code /////////
<View
android:id="@ id/mtv_crossLine"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="@dimen/margin_design_52"
android:layout_marginEnd="@dimen/margin_design_52"
android:background="@color/gray"
app:layout_constraintBottom_toBottomOf="@ id/mtv_or"
app:layout_constraintEnd_toEndOf="@ id/btnLogin"
app:layout_constraintStart_toStartOf="@ id/btnLogin"
app:layout_constraintTop_toTopOf="@ id/mtv_or" />
<com.google.android.material.textview.MaterialTextView
android:id="@ id/mtv_or"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="@dimen/margin_design_15"
android:text="@string/or"
android:textAllCaps="true"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="@color/primaryTextColor"
app:layout_constraintEnd_toEndOf="@ id/btnLogin"
app:layout_constraintStart_toStartOf="@ id/btnLogin"
app:layout_constraintTop_toBottomOf="@ id/mbtn_signup" />
<com.google.android.material.textview.MaterialTextView
android:id="@ id/mbtn_loginSocialLabel"
style="@style/AppTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_design_30"
android:text="@string/login_social_media_label"
app:layout_constraintEnd_toEndOf="@ id/btnLogin"
app:layout_constraintStart_toStartOf="@ id/btnLogin"
app:layout_constraintTop_toBottomOf="@ id/mtv_or" />
<LinearLayout
android:id="@ id/ib_twitter_login"
android:layout_width="0dp"
android:layout_height="@dimen/margin_design_162"
android:layout_marginTop="@dimen/margin_design_12"
android:background="@drawable/bg_btn_rounded_corner_twitter"
android:clickable="true"
android:focusable="true"
app:layout_constraintBottom_toBottomOf="@ id/ib_google_login"
app:layout_constraintEnd_toStartOf="@ id/mtv_or"
app:layout_constraintStart_toStartOf="@ id/btnLogin"
app:layout_constraintTop_toBottomOf="@ id/mbtn_loginSocialLabel">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter"
android:textAllCaps="false"
app:srcCompat="@drawable/twitter_bird_white"
android:contentDescription="@string/login" />
</LinearLayout>
<LinearLayout
android:id="@ id/ib_google_login"
android:layout_width="0dp"
android:layout_height="@dimen/margin_design_162"
android:layout_marginTop="@dimen/margin_design_12"
android:clickable="true"
android:focusable="true"
android:background="@drawable/bg_btn_white_rounded_login"
app:layout_constraintEnd_toEndOf="@ id/btnLogin"
app:layout_constraintStart_toEndOf="@ id/mtv_or"
app:layout_constraintTop_toBottomOf="@ id/mbtn_loginSocialLabel">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_design_19"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_google_g_icon"
android:textAllCaps="false"
android:contentDescription="@string/login" />
</LinearLayout>
//////// Buggy Code /////////
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
dimen.xml
.
.
<dimen name="margin_design_3">1dp</dimen>
<dimen name="margin_design_6">2dp</dimen>
<dimen name="margin_design_12">4dp</dimen>
<dimen name="margin_design_15">5dp</dimen>
<dimen name="margin_design_19">6dp</dimen>
<dimen name="margin_design_20">7dp</dimen>
<dimen name="margin_design_21">7dp</dimen>
<dimen name="margin_design_24">8dp</dimen>
<dimen name="margin_design_27">9dp</dimen>
<dimen name="margin_design_30">10dp</dimen>
<dimen name="margin_design_33">11dp</dimen>
<dimen name="margin_design_36">12dp</dimen>
<dimen name="margin_design_40">13dp</dimen>
<dimen name="margin_design_43">14dp</dimen>
<dimen name="margin_design_45">15dp</dimen>
<dimen name="margin_design_47">15dp</dimen>
<dimen name="margin_design_48">16dp</dimen>
<dimen name="margin_design_52">17dp</dimen>
<dimen name="margin_design_56">18dp</dimen>
<dimen name="margin_design_60">20dp</dimen>
<dimen name="margin_design_63">21dp</dimen>
<dimen name="margin_design_67">22dp</dimen>
<dimen name="margin_design_71">23dp</dimen>
<dimen name="margin_design_75">25dp</dimen>
<dimen name="margin_design_78">26dp</dimen>
<dimen name="margin_design_80">26dp</dimen>
<dimen name="margin_design_81">27dp</dimen>
<dimen name="margin_design_86">28dp</dimen>
<dimen name="margin_design_87">29dp</dimen>
<dimen name="margin_design_90">30dp</dimen>
<dimen name="margin_design_93">31dp</dimen>
<dimen name="margin_design_96">32dp</dimen>
<dimen name="margin_design_100">33dp</dimen>
<dimen name="margin_design_103">34dp</dimen>
<dimen name="margin_design_105">35dp</dimen>
<dimen name="margin_design_110">36dp</dimen>
<dimen name="margin_design_120">40dp</dimen>
<dimen name="margin_design_128">43dp</dimen>
<dimen name="margin_design_137">45dp</dimen>
<dimen name="margin_design_140">46dp</dimen>
<dimen name="margin_design_143">47dp</dimen>
<dimen name="margin_design_160">53dp</dimen>
<dimen name="margin_design_162">54dp</dimen>
<dimen name="margin_design_170">56dp</dimen>
<dimen name="margin_design_175">58dp</dimen>
<dimen name="margin_design_178">59dp</dimen>
<dimen name="margin_design_180">60dp</dimen>
<dimen name="margin_design_196">65dp</dimen>
<dimen name="margin_design_258">86dp</dimen>
<dimen name="margin_design_289">96dp</dimen>
<dimen name="margin_design_307">102dp</dimen>
<dimen name="margin_design_340">108dp</dimen>
<dimen name="margin_design_390">115dp</dimen>
<dimen name="margin_design_407">135dp</dimen>
<dimen name="margin_design_498">166dp</dimen>
<dimen name="margin_design_508">170dp</dimen>
<dimen name="margin_design_550">183dp</dimen>
<dimen name="margin_design_590">196dp</dimen>
<dimen name="margin_design_630">210dp</dimen>
<dimen name="margin_design_906">302dp</dimen>
.
.
трассировка стека:
java.lang.RuntimeException: Unable to resume activity {com.jutt.professoryapp.internal/com.jutt.professoryapp.view.activities.LoginActivity}: android.view.InflateException: Binary XML file line #119: Binary XML file line #119: Error inflating class com.google.android.material.textview.MaterialTextView
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4156)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4258)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3361)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #119: Binary XML file line #119: Error inflating class com.google.android.material.textview.MaterialTextView
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
at com.jutt.professoryapp.view.fragments.LoginFragment.onCreateView(LoginFragment.kt:52)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2935)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:539)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:276)
at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1632)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:455)
at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2389)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2145)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2083)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1985)
at androidx.fragment.app.FragmentController.execPendingActions(FragmentController.java:451)
at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:414)
at com.jutt.professoryapp.view.activities.LoginActivity.onResume(LoginActivity.kt:49)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1286)
at android.app.Activity.performResume(Activity.java:6987)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4145)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4258)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3361)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: android.view.InflateException: Binary XML file line #119: Error inflating class com.google.android.material.textview.MaterialTextView
at android.view.LayoutInflater.createView(LayoutInflater.java:657)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
at com.jutt.professoryapp.view.fragments.LoginFragment.onCreateView(LoginFragment.kt:52)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2935)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:539)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:276)
at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1632)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:455)
at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2389)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2145)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2083)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1985)
at androidx.fragment.app.FragmentController.execPendingActions(FragmentController.java:451)
at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:414)
at com.jutt.professoryapp.view.activities.LoginActivity.onResume(LoginActivity.kt:49)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1286)
at android.app.Activity.performResume(Activity.java:6987)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4145)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4258)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3361)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:631)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:716)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:847)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
at com.jutt.professoryapp.view.fragments.LoginFragment.onCreateView(LoginFragment.kt:52)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2935)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:539)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:276)
at androidx.fragment.app.FragmentStore.moveToExpectedState(FragmentStore.java:112)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1632)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:455)
at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2389)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2145)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2083)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1985)
at androidx.fragment.app.FragmentController.execPendingActions(FragmentController.java:451)
at androidx.fragment.app.FragmentActivity.onResume(FragmentActivity.java:414)
at com.jutt.professoryapp.view.activities.LoginActivity.onResume(LoginActivity.kt:49)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1286)
at android.app.Activity.performResume(Activity.java:6987)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4145)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4258)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3361)
at android.app.ActivityThread.access$1100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7237)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=47; index=1576
at android.content.res.StringBlock.get(StringBlock.java:65)
at android.content.res.XmlBlock$Parser.getPooledString(XmlBlock.java:459)
at android.content.res.TypedArray.loadStringValueAt(Ty
любая помощь будет оценена!!!
Комментарии:
1. Включите трассировку стека сбоя и добавьте соответствующие строки в другой блок кода
2. добавлена трассировка стека
3. Какова базовая тема вашего приложения в styles.xml ?
4. тема приложения
Theme.MaterialComponents.Light.NoActionBar
5. Работает ли это, если вы вместо
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1
, используетеapp:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1
? Я думаю, что область Android работает только на последних версиях Android. Область приложения должна работать для всех.
Ответ №1:
Спасибо, @Fred за подсказку в комментариях, проблема заключалась в android:textAllCaps
том, что должно быть app:textAllCaps
в MaterialTextView, как только я исправил, что все работает нормально.
<com.google.android.material.textview.MaterialTextView
android:id="@ id/mtv_or"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:padding="@dimen/margin_design_15"
android:text="@string/or"
android:textAllCaps="true" **<-- Problem**
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textColor="@color/primaryTextColor"
app:layout_constraintEnd_toEndOf="@ id/btnLogin"
app:layout_constraintStart_toStartOf="@ id/btnLogin"
app:layout_constraintTop_toBottomOf="@ id/mbtn_signup" />