Fatal Exception: android.view.InflateException: Binary XML file line #20 - android

I'm very new to android development. I know there are many questions like this in stack overflow. I referred those questions but I didn't get solution yet. Whenever I long press the EditText which is inside of TextInputLayout app getting crash.
Fatal Exception: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class TextView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.view.View.inflate(View.java:19805)
at android.widget.Editor.getTextThumbnailBuilder(Editor.java:2112)
at android.widget.Editor.performLongClick(Editor.java:1014)
at android.widget.TextView.performLongClick(TextView.java:9240)
at android.view.View$CheckForLongPress.run(View.java:21142)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by android.view.InflateException: Binary XML file line #20: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.view.View.inflate(View.java:19805)
at android.widget.Editor.getTextThumbnailBuilder(Editor.java:2112)
at android.widget.Editor.performLongClick(Editor.java:1014)
at android.widget.TextView.performLongClick(TextView.java:9240)
at android.view.View$CheckForLongPress.run(View.java:21142)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by java.lang.UnsupportedOperationException: Failed to resolve attribute at index 24: TypedValue{t=0x3/d=0x285 "res/color/primary_text_material_light.xml" a=1 r=0x106010a}
at android.content.res.TypedArray.getColor(TypedArray.java:447)
at android.widget.TextView.<init>(TextView.java:738)
at android.widget.TextView.<init>(TextView.java:671)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:60)
at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:972)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1031)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.view.View.inflate(View.java:19805)
at android.widget.Editor.getTextThumbnailBuilder(Editor.java:2112)
at android.widget.Editor.performLongClick(Editor.java:1014)
at android.widget.TextView.performLongClick(TextView.java:9240)
at android.view.View$CheckForLongPress.run(View.java:21142)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Caused by android.view.InflateException
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:782)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:618)
Caused by java.lang.UnsupportedOperationException
android.content.res.TypedArray.getColor (TypedArray.java:447)
android.widget.TextView.<init> (TextView.java:738)
android.widget.TextView.<init> (TextView.java:671)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:618)
My XML file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/sign_in_relative_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/sign_in_bg"
class = "com.fitficfitz.android.ui.login.SignInFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:background="#color/colorPrimary"
android:paddingLeft="#dimen/size_5"
>
<ImageView
android:id="#+id/backButton"
android:layout_width="#dimen/size_20"
android:layout_height="#dimen/size_20"
android:layout_marginLeft="#dimen/size_10"
android:src="#drawable/back_btn"/>
<TextView
android:id="#+id/more_session_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SIGN IN"
android:textStyle="normal"
android:textSize="24sp"
android:textColor="#color/white"
android:paddingLeft="#dimen/size_30"
/>
<include
android:id="#+id/book_toolbar"
layout="#layout/book_session_toolbar"/>
</LinearLayout>
<LinearLayout
android:id="#+id/social_sign_in_linear_layout"
android:layout_width="match_parent"
android:layout_height="#dimen/size_126"
android:orientation="horizontal"
android:layout_marginTop="#dimen/size_50">
<FrameLayout
android:id="#+id/twitter_sign_in"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="#dimen/weight_1"
android:visibility="gone">
<TextView
android:id="#+id/twitter_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="#dimen/size_10"
android:drawableTop="#drawable/twitter"
android:gravity="center"
android:letterSpacing="#dimen/letter_spacing_040"
android:text="#string/login_with_twitter"
android:textColor="#color/white"
android:textSize="#dimen/font_13"
tools:ignore="UnusedAttribute"/>
</FrameLayout>
<View
android:id="#+id/social_divider_view"
android:layout_width="#dimen/size_1"
android:layout_height="#dimen/size_126"
android:alpha="0.2"
android:visibility="gone"
android:background="#color/grey_eff6fc"/>
<FrameLayout
android:id="#+id/facebook_sign_in"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="#dimen/weight_1">
<TextView
android:id="#+id/facebook_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="#dimen/size_10"
android:drawableTop="#drawable/facebook"
android:gravity="center"
android:letterSpacing="#dimen/letter_spacing_040"
android:text="#string/login_in_with_facebook"
android:textColor="#color/white"
android:textSize="#dimen/font_13"
tools:ignore="UnusedAttribute"/>
</FrameLayout>
</LinearLayout>
<View
android:id="#+id/social_horizontal_divider_view"
android:layout_width="match_parent"
android:layout_height="#dimen/size_1"
android:layout_below="#+id/social_sign_in_linear_layout"
android:layout_marginBottom="#dimen/size_50"
android:alpha="0.2"
android:background="#color/grey_eff6fc"/>
<ImageView
android:id="#+id/username_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/social_horizontal_divider_view"
android:layout_marginBottom="#dimen/size_20"
android:layout_marginLeft="#dimen/size_28"
android:layout_marginRight="#dimen/size_28"
android:contentDescription="#null"
android:src="#drawable/username"
android:layout_marginTop="#dimen/size_25"/>
<android.support.design.widget.TextInputLayout
android:theme="#style/TextLabel"
android:id="#+id/input_layout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/username_image_view"
android:layout_toRightOf="#id/username_image_view"
android:layout_marginTop="#dimen/size_10"
android:layout_below="#+id/social_horizontal_divider_view">
<EditText
android:layout_marginTop="10dp"
android:id="#+id/username_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:hint="Email Address"
android:inputType="textEmailAddress"
android:paddingBottom="#dimen/size_16"
android:translationY="10dp"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_13"/>
</android.support.design.widget.TextInputLayout>
<View
android:id="#+id/username_base_view"
android:layout_width="wrap_content"
android:layout_height="#dimen/size_1"
android:layout_alignLeft="#id/input_layout_username"
android:layout_alignParentRight="true"
android:layout_below="#id/input_layout_username"
android:alpha="0.2"
android:background="#color/grey_eff6fc"
android:paddingBottom="#dimen/size_10"/>
<ImageView
android:id="#+id/password_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/username_base_view"
android:layout_marginTop="#dimen/size_30"
android:contentDescription="#null"
android:paddingBottom="#dimen/size_20"
android:paddingLeft="#dimen/size_28"
android:paddingRight="#dimen/size_28"
android:src="#drawable/password"
/>
<android.support.design.widget.TextInputLayout
android:theme="#style/TextLabel"
android:id="#+id/input_layout_passwrod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/username_base_view"
android:layout_toEndOf="#id/password_image_view"
android:layout_marginTop="#dimen/size_10"
android:layout_toRightOf="#id/password_image_view">
<EditText
android:id="#+id/password_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#null"
android:hint="#string/password"
android:inputType="textPassword"
android:paddingBottom="#dimen/size_16"
android:paddingTop="#dimen/size_10"
android:textColor="#color/white"
android:textColorHint="#color/white"
android:textSize="#dimen/font_13"
/>
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="#+id/forgot_password_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/username_base_view"
android:layout_marginEnd="#dimen/size_20"
android:layout_marginRight="#dimen/size_20"
android:layout_marginTop="#dimen/size_30"
android:clickable="true"
android:src="#drawable/forgot_password"/>
<View
android:id="#+id/password_base_view"
android:layout_width="wrap_content"
android:layout_height="#dimen/size_1"
android:layout_alignLeft="#id/input_layout_passwrod"
android:layout_alignParentRight="true"
android:layout_below="#id/input_layout_passwrod"
android:alpha="0.2"
android:background="#color/grey_eff6fc"/>
<Button
android:id="#+id/sign_in_button"
style="#style/EndButtonStyle"
android:layout_alignParentBottom="true"
android:layout_marginTop="#dimen/size_32"
android:text="#string/sign_in_button"/>
<LinearLayout
android:id="#+id/sign_up_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/sign_in_button"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="#+id/sign_up_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sign_up_text"
android:textColor="#color/grey_a8a9ab"
android:textSize="#dimen/font_13"/>
<TextView
android:id="#+id/sign_up_question_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/size_4"
android:clickable="true"
android:text="#string/sign_up_question"
android:textColor="#color/grey_a8a9ab"
android:textSize="#dimen/font_14"/>
</LinearLayout>
<FrameLayout
android:id="#+id/login_progress_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="#dimen/alpha_04"
android:background="#color/black"
android:clickable="true"
android:focusable="true"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>
</RelativeLayout>
primary_text_material_light.xml code:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="#color/primary_text_disabled_material_light"/>
<item android:color="#color/primary_text_default_material_light"/>
</selector>
style/TextLabel code:
<style name="TextLabel" parent="TextAppearance.AppCompat">
<item name="android:textColorHint">#color/white</item>
<item name="colorAccent">#color/white</item>
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
</style>

I found the issue after spending some hours. The issue is I have missed to add textColorHighlight in my style for TextInputLayout. So, I changed my theme from
<style name="TextLabel" parent="TextAppearance.AppCompat">
<item name="android:textColorHint">#color/white</item>
<item name="colorAccent">#color/white</item>
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
</style>
to
<style name="TextLabel" parent="#android:style/TextAppearance.Widget.TextView">
<item name="android:textColorHint">#color/white</item>
<item name="colorAccent">#color/white</item>
<item name="colorControlNormal">#color/white</item>
<item name="colorControlActivated">#color/white</item>
<item name="android:textColorHighlight">#color/grey_5f6971</item>
<item name="android:textColorLink">#color/white</item>
</style>
Thanks guys who are helping me in comment and answer section.

It just basically means that it was not able to find primary_text_material_light.xml in your resources res/color.xml
Please paste your xml code to get detailed answer.

library android support 7 should add rightly.you should remove and add libray and then clean your project.

#line number 20 android:id="#+id/backButton"..... .
In your java file do this ImageView img = (ImageView)findViewById(R.id.backButton);
you might be typecasting R.id.backButton with some other view type

Related

Error inflating class ImageButton Stops app from starting

My app fails to start because of Error inflating class ImageButton, Because of this the phone says "app has stopped" Etc.
I am using firebase test lab to debug the problem
the Errors occur on samsung devices specifically A20, s7 Edge , s7(tested with firebase same problem)
I am new to android and have tried many solutions from google and SO none have worked sofar
Here is the error report on firebase
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartpractice.smartpracticesmartapp/com.smartpractice.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #117: Binary XML file line #117: Error inflating class ImageButton
FATAL EXCEPTION: main
Process: com.smartpractice.smartpracticesmartapp, PID: 26921
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.smartpractice.smartpracticesmartapp/com.smartpractice.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #117: Binary XML file line #117: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
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 #117: Binary XML file line #117: Error inflating class ImageButton
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.smartpractice.myapplication.MainActivity.onCreate(MainActivity.java:14)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
... 9 more
Caused by: android.view.InflateException: Binary XML file line #117: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
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.rInflate(LayoutInflater.java:855)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:810)
at android.view.LayoutInflater.inflate(LayoutInflater.java:527)
... 17 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070089
at android.content.res.Resources.getValue(Resources.java:2558)
at androidx.appcompat.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:331)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
at androidx.appcompat.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
at androidx.appcompat.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
at androidx.appcompat.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:79)
at androidx.appcompat.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:69)
at androidx.appcompat.app.AppCompatViewInflater.createImageButton(AppCompatViewInflater.java:202)
at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:122)
at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:758)
Here is the XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:id="#+id/relativeLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/ic_launcher_background"
tools:context=".MainActivity">
<com.google.android.flexbox.FlexboxLayout
android:id="#+id/flexboxLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexWrap="wrap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.863"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline7">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="48dp"
android:fontFamily="#font/nunito"
android:gravity="center_horizontal"
android:text="#string/welcome_to_smartpractice"
android:textSize="24sp"
app:fontFamily="#font/nunito"
app:layout_alignSelf="baseline"
tools:layout_editor_absoluteY="100dp"
tools:targetApi="jelly_bean" />
<TextView
android:id="#+id/textView7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimaryDark"
android:gravity="center_horizontal|fill_vertical"
android:text="#string/docsharesmart"
android:textColor="#color/ic_launcher_background"
app:layout_alignSelf="flex_end"
tools:layout_editor_absoluteY="16dp" />
</com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
app:alignContent="center"
app:alignItems="stretch"
app:flexDirection="row"
app:flexWrap="nowrap"
app:justifyContent="space_between"
app:layout_constraintBottom_toTopOf="#+id/guideline7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/imageView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="#string/logo1"
app:layout_alignSelf="center"
app:srcCompat="#drawable/smartpractice_logo_02"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="-46dp" />
<ImageButton
android:id="#+id/LoginScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null"
android:contentDescription="#string/loginscreen"
app:layout_alignSelf="center"
app:layout_wrapBefore="false"
app:srcCompat="#drawable/ic_more_vert_black_24dp"
tools:layout_editor_absoluteX="248dp"
tools:layout_editor_absoluteY="134dp" />
</com.google.android.flexbox.FlexboxLayout>
<com.google.android.flexbox.FlexboxLayout
android:id="#+id/flexboxLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:alignContent="stretch"
app:alignItems="stretch"
app:flexWrap="wrap"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/flexboxLayout"
app:layout_constraintVertical_bias="0.146">
Here is line 117 from the error
<ImageButton
android:id="#+id/UploadButton"
android:layout_width="300dp"
android:layout_height="209dp"
android:background="#android:color/transparent"
app:layout_constraintTop_toBottomOf="#+id/flexboxLayout"
app:srcCompat="#drawable/upload_files_upload"
android:contentDescription="#string/todo" />
</com.google.android.flexbox.FlexboxLayout>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="185dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
It means upload_files_upload is not found in drawble folder, well this can be a case, where your file may present in drawable-24 but not in drawble folder, in that case this problem still arise. The point is your file must be in all drawble folder.
The reason for your error is that the upload_files_upload is not in your drawable folder :
<ImageButton
android:id="#+id/UploadButton"
android:layout_width="300dp"
android:layout_height="209dp"
android:background="#android:color/transparent"
app:layout_constraintTop_toBottomOf="#+id/flexboxLayout"
app:srcCompat="#drawable/upload_files_upload"// this line
android:contentDescription="#string/todo" />
I have solved The Issue I changed app:srcCompat="#drawable/upload_files_upload"// to android:src="#drawable/upload_files_upload"
So the problem was by app:srcCompat I changed it to Android:src and it works fine now

How to fix 'Error inflating class EditText' in Android XML Layout

I am getting following error for the line #30 i.e. first line of first EditText in the provided code. This XML is basically associated with an Activity. The error is while binding XML inside activity
setContentView(R.layout.activity_login)
The error is as follows:
Caused by android.view.InflateException: Binary XML file line #30: Binary XML file line #30: Error inflating class EditText
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.pockethcm.greytrix.test.LoginActivity.onCreate(LoginActivity.kt:39)
at android.app.Activity.performCreate(Activity.java:6268)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2370)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2477)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5468)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:671)
I have tried couple of things explained in other answers but none of them actually helped me. I am not using any drawable resource for that EditText.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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"
android:background="#drawable/login_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.pockethcm.greytrix.test.LoginActivity"
>
<LinearLayout
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:paddingStart="#dimen/_20sdp"
android:paddingEnd="#dimen/_20sdp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/login_layout">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="match_parent"
android:layout_height="96dp"
android:src="#drawable/pocketlogosplash"
app:civ_border_width="2dp"
app:civ_circle_background_color="#color/colorWhite"
app:civ_border_color="#bcbcbc"/>
<EditText
android:layout_width="match_parent"
android:backgroundTint="#color/colorWhite"
android:layout_height="wrap_content"
android:hint="Company Code"
android:textColorHint="#color/colorWhite"
android:layout_marginTop="20dp"
android:drawableStart="#drawable/ic_store_white_24dp"
android:drawablePadding="10dp"
android:textColor="#color/colorWhite"
android:id="#+id/company_code"
android:imeOptions="actionNext"
android:maxLines="1"
android:singleLine="true"/>
<EditText
android:layout_width="match_parent"
android:backgroundTint="#color/colorWhite"
android:layout_height="wrap_content"
android:hint="Employee Code"
android:textColorHint="#color/colorWhite"
android:layout_marginTop="20dp"
android:drawableStart="#drawable/ic_person_black_24dp"
android:drawablePadding="10dp"
android:textColor="#color/colorWhite"
android:id="#+id/employee_code"
android:drawableTint="#color/colorWhite"
android:imeOptions="actionNext"
android:maxLines="1"
android:singleLine="true"/>
</LinearLayout>
</ScrollView>
EditText widget should load normally but the activity is crashing with error above.
Providing additional info:
compileSdkVersion 28
minSdkVersion 21
targetSdkVersion 28
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
You should set left drawable programmatically if its vector for pre kitkat.
company_code.setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(this,R.drawable.ic_store_white_24dp), null, null, null);```
Which android version you are using, I think you use Vector Drawable in EditText, But Vector Drawable support after KitKat.

Failed to inflate ColorStateList, leaving it to the framework java.lang.UnsupportedOperationException: Can't convert to color: type=0x2

I have a login part and I use TextInputLayout for email and password. Both of them are the same. Also I use Data binding to show the Error message.
The error is happening on API < 20 when it should show an Error Hint.
#Override
public void showEmailError() {
inputLayoutEmail.setError(sInvalidEmail);
}
xml layout :
<android.support.design.widget.TextInputLayout
android:id="#+id/til_email"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="#dimen/default_margin_16dp"
android:layout_marginRight="#dimen/default_margin_16dp"
android:layout_marginTop="16dp"
android:layout_below="#id/login_img_logo"
android:layout_centerHorizontal="true"
android:textColorHint="#color/gray"
android:background="#drawable/login_edittext"
android:errorEnabled="#{viewmodel.obEmailErrorVisibility}"
>
<EditText
android:id="#+id/et_login"
android:layout_height="#dimen/login_view_height"
android:layout_width="#dimen/login_view_width"
android:inputType="text"
android:maxLength="50"
android:hint="#string/activity_login_hint_email"
android:text="#={viewmodel.email}"
android:textColor="#color/black"
android:textColorHint="#color/gray"
android:paddingLeft="#dimen/default_margin_16dp"
android:enabled="#{viewmodel.obIsEmailFieldEnabled}"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/til_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/default_margin_16dp"
android:layout_marginRight="#dimen/default_margin_16dp"
android:layout_marginTop="#dimen/default_margin_8dp"
android:layout_below="#id/til_email"
android:layout_centerHorizontal="true"
android:textColorHint="#color/gray"
android:background="#drawable/login_edittext"
android:errorEnabled="#{viewmodel.obPassErrorVisibility}"
>
<EditText
android:id="#+id/et_password"
android:layout_width="#dimen/login_view_width"
android:layout_height="#dimen/login_view_height"
android:hint="#string/activity_login_hint_password"
android:maxLength="50"
android:inputType="textPassword"
android:text="#={viewmodel.password}"
android:textColor="#color/black"
android:textColorHint="#color/gray"
android:paddingLeft="#dimen/default_margin_16dp"
android:enabled="#{viewmodel.obIsPassFieldEnabled}"
/>
</android.support.design.widget.TextInputLayout>
as background I use
login_edittext.xml
<solid android:color="#color/white" />
<corners
android:radius="#dimen/login_edittext_radius"
/>
I have check similar answers, but most of them are related to styles
Can't convert to color: type=0x2 error when inflating layout in fragment but only on Samsung Galaxy and Note 4
So, I have finished with this solution that works for me.
To TextInputLayout add this string
app:errorTextAppearance="#style/MyAppTheme.TextInputLayout"
And add new style to styles.xml
<style name="MyAppTheme.TextInputLayout" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/red</item>
</style>

Custom RatingBar Shows different number of stars when on api 23

When setting RatingBar in xml file and set android:drawableProgress to custom drawable I've created (as described here) it shows 5 stars in the preview screen of android studio with api 22 but when I set the api target to api 23 it shows 1 star but the ratingbar (android:width="wrap_content") is at the same width as it is with 5 stars. This is also checked on cellular phones with Lollipop and marshmallow OS (Same behavior as described).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/spacing_standard"
android:orientation="vertical"
android:background="#color/sfly_orange"
android:fillViewport="true">
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/thank_you_label_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/order_confirmation_thank_you"
android:textColor="#android:color/white"
android:textSize="#dimen/rate_app_text_size_largest"
android:gravity="center"
app:typeface="medium"
android:layout_marginTop="#dimen/spacing_standard"/>
<ImageView
android:layout_width="#dimen/rate_app_image_width"
android:src="#drawable/rate_icon"
android:layout_gravity="center_horizontal"
android:layout_marginTop="#dimen/rate_app_spacing_standard"
android:layout_height="#dimen/rate_app_image_height"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/rate_app_spacing_standard">
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/order_number_label_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
app:typeface="medium"
android:text="#string/order_confirmation_order_number_label"
android:textColor="#android:color/white"
android:textSize="#dimen/rate_app_text_size_normal"/>
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/order_number_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
app:typeface="medium"
android:layout_marginTop="#dimen/spacing_standard"
android:textColor="#android:color/white"
android:textSize="#dimen/rate_app_text_size_larger"/>
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/order_confirmation_details_label_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/order_confirmation_details_label"
android:layout_marginTop="#dimen/spacing_standard_large"
android:textAlignment="center"
android:lineSpacingExtra="#dimen/rate_app_text_line_spacing"
android:gravity="center"
app:typeface="oblique"
android:textColor="#android:color/white"
android:textSize="#dimen/rate_app_text_size_normal"
tools:ignore="UnusedAttribute"/>
<RatingBar
android:id="#+id/rate_app_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/rate_app_spacing_standard"
android:numStars="#integer/rating_bar_number_of_stars"
android:stepSize="#integer/rating_bar_step"
android:minHeight="#dimen/button_height"
android:maxHeight="#dimen/button_height"
style="?android:attr/ratingBarStyle"
android:layout_gravity="center"
android:progressDrawable="#drawable/rating_bar_star_style"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:layout_marginTop="#dimen/rate_app_spacing_standard">
<com.shutterfly.android.commons.common.ui.TypefacedTextView
android:id="#+id/rate_app_button"
android:layout_width="#dimen/button_width"
android:layout_height="#dimen/button_height"
android:gravity="center"
android:background="#drawable/button_white_background"
android:paddingLeft="#dimen/spacing_standard"
android:paddingRight="#dimen/spacing_standard"
android:text="#string/rate_shutterfly"
android:textAllCaps="true"
android:textColor="#color/sfly_orange"
android:textSize="#dimen/rate_app_text_size_normal_larger"
app:typeface="medium"/>
<com.shutterfly.android.commons.common.ui.TypefacedButton
android:id="#+id/return_to_store_button"
android:layout_width="#dimen/button_width"
android:layout_height="#dimen/button_height"
android:paddingLeft="#dimen/spacing_standard"
android:layout_marginTop="#dimen/spacing_standard"
android:layout_gravity="bottom|center_horizontal"
android:paddingRight="#dimen/spacing_standard"
android:text="#string/order_confirmation_return_to_store"
style="?android:attr/borderlessButtonStyle"
android:textAllCaps="true"
android:textColor="#color/white"
android:textSize="#dimen/rate_app_text_size_normal"
app:btnTypeface="medium"
android:layout_marginBottom="#dimen/spacing_standard"
android:background="#drawable/button_orange_background"/>
</LinearLayout>
</LinearLayout>
Maybe the default numStars value has changed.
When I set it in the xml file, it works fine.
<RatingBar
...
numStars="5" />
It could be a layout issue too, if wrap_content doesn't have enough space to display 5 stars. Maybe you have qualifiers for Api 23 ? If not and it works fine for <23, do not mind about it.
You can use custom style as below and use that style in your layout file:
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/rating_bar_star_style</item>
<item name="android:minHeight">#dimen/button_height</item>
<item name="android:maxHeight">#dimen/button_height</item>
<item name="android:numStars">#integer/rating_bar_number_of_stars</item>
<item name="android:stepSize">#integer/rating_bar_step</item>
</style>
And use this in your layout as below:
<RatingBar
android:id="#+id/rate_app_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/rate_app_spacing_standard"
style="#style/CustomRatingBar"
android:layout_gravity="center"/>
I think there is some problem with the theme you are using. Please try AppTheme instead of any other and the above code might work for you.

Expected receiver of type, but got android.support.v7.widget.TintContextWrapper

I have tried a lot to find solution. As Same Question found but It doesn't have answer what I want.
I have following XML File:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/add_appointment_parent_layout"
tools:context="com.potionowl.app.activity.AppointmentAddActivity">
<include layout="#layout/layout_toolbar"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="#dimen/padding_small"
android:layout_margin="#dimen/padding_medium"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatSpinner
android:id="#+id/add_appointment_doctor_spinner"
android:layout_width="match_parent"
android:prompt="#string/string_select_doctor_patient"
android:spinnerMode="dialog"
android:layout_margin="#dimen/padding_medium"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_margin="#dimen/padding_medium"
android:layout_height="wrap_content"
android:baselineAligned="false">
<android.support.design.widget.TextInputLayout
android:id="#+id/add_appointment_date_title"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_margin="#dimen/padding_very_small"
android:layout_height="wrap_content">
<EditText
android:id="#+id/add_appointment_date_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/string_add_app_date_for_appointment"
android:focusable="false"
android:onClick="PickDate"
android:singleLine="true"
android:inputType="datetime"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/add_appointment_time_title"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_margin="#dimen/padding_very_small"
android:layout_height="wrap_content">
<EditText
android:id="#+id/add_appointment_time_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/string_add_app_time_for_appointment"
android:focusable="false"
android:onClick="PickTime"
android:singleLine="true"
android:inputType="datetime"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/add_appointment_symptoms_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/padding_medium">
<android.support.design.widget.TextInputEditText
android:id="#+id/add_appointment_symptoms_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:gravity="start"
android:hint="#string/string_add_app_symptoms"
android:lines="5"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:layout_width="wrap_content"
android:layout_gravity="center"
style="#style/Base.Widget.AppCompat.Button.Colored"
android:layout_margin="#dimen/padding_medium"
android:onClick="addAppointmentButtonClick"
android:layout_height="wrap_content"
android:text="#string/apply_for_appointment"/>
</LinearLayout>
</LinearLayout>
I am getting Errors like:
05-10 23:27:16.942 13455-13455/com.potionowl.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.potionowl.app, PID: 13455
java.lang.IllegalArgumentException: Expected receiver of type com.potionowl.app.activity.AppointmentAddActivity, but got android.support.v7.widget.TintContextWrapper
at java.lang.reflect.Method.invoke(Native Method)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4456)
at android.view.View.performClick(View.java:5207)
at android.view.View$PerformClick.run(View.java:21168)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
I don't know why it happens. Is there any solution? Thank you.
This is related to the way AppCompat inflates your layout. Try adding a programmatic onClick listener to your buttons rather than doing it within XML.
There's a discussion about it on Google Code. It's because you are using the AppCompat Buttons.
You could use butterknife annotations instead
#OnClick(R.id.IdForAppCompatButton)
public void doAction() {doSomething();}
In my case the problem was from setting the android:theme attribute to the view, (and also is related to the AppCompat library ... see #Peter Marozzi's answer).
So I simply removed the android: namespace from this line (from the view's style):
<item name="android:theme">#style/someTheme</item>
and make it likes:
<item name="theme">#style/someTheme</item>
and it works fine.
The interactive note is the problem is only on high-level APIs (23 I tested) and on low-level APIs (16 and 19 I tested) both methods (with or without android: namespace) work.
It worked for me to register the listener on the current DialogFragment class:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
dialogView = inflater.inflate(/*your layout*/, container, false);
dialogView.findViewById(R.id.close_button).setOnClickListener(this);
return dialogView;
}
#Override
public void onClick(View v) {
//Handle the button click event here
}

Categories

Resources