0

I created an EditText as follows:

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
    android:orientation="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="false">
    .
    .
    .
    <android.support.v7.widget.AppCompatEditText
        android:id="@+id/id2"
        style="@style/myStyle2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:background="@drawable/custom_edittext"
        android:ems="10"
        android:gravity="top"
        android:hint="@string/default_hint"
        android:inputType="textMultiLine"
        android:minLines="6"
        android:paddingBottom="17dp"
        android:paddingLeft="19dp"
        android:paddingRight="19dp"
        android:paddingTop="17dp" />
    .
    .
    .

</LinearLayout>

When I long press any content written in the EditText box, my app crashes and logcat gives me this:

android.view.InflateException: Binary XML file line #19: Error inflating class android.support.v7.widget.ActionBarContextView
E/AndroidRuntime( 6991):    at android.view.LayoutInflater.createView(LayoutInflater.java:637)
E/AndroidRuntime( 6991):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:747)
E/AndroidRuntime( 6991):    at android.view.LayoutInflater.inflate(LayoutInflater.java:486)
E/AndroidRuntime( 6991):    at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
E/AndroidRuntime( 6991):    at android.support.v7.widget.ViewStubCompat.inflate(ViewStubCompat.java:200)
E/AndroidRuntime( 6991):    at android.support.v7.app.AppCompatDelegateImplV7.startSupportActionModeFromWindow(AppCompatDelegateImplV7.java:792)
E/AndroidRuntime( 6991):    at android.support.v7.app.AppCompatDelegateImplV7.startSupportActionMode(AppCompatDelegateImplV7.java:696)
E/AndroidRuntime( 6991):    at android.support.v7.app.AppCompatDelegateImplV14$AppCompatWindowCallbackV14.startAsSupportActionMode(AppCompatDelegateImplV14.java:187)
E/AndroidRuntime( 6991):    at android.support.v7.app.AppCompatDelegateImplV14$AppCompatWindowCallbackV14.onWindowStartingActionMode(AppCompatDelegateImplV14.java:171)
E/AndroidRuntime( 6991):    at android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode(WindowCallbackWrapper.java:145)
E/AndroidRuntime( 6991):    at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2755)
E/AndroidRuntime( 6991):    at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2742)
E/AndroidRuntime( 6991):    at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:713)
E/AndroidRuntime( 6991):    at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:713)
E/AndroidRuntime( 6991):    at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:713)
E/AndroidRuntime( 6991):    at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:713)
E/AndroidRuntime( 6991):    at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:713)
E/AndroidRuntime( 6991):    at android.view.View.startActionMode(View.java:5148)
E/AndroidRuntime( 6991):    at android.widget.Editor.startSelectionActionMode(Editor.java:1575)
E/AndroidRuntime( 6991):    at android.widget.Editor.performLongClick(Editor.java:907)
E/AndroidRuntime( 6991):    at android.widget.TextView.performLongClick(TextView.java:8793)
E/AndroidRuntime( 6991):    at android.view.View$CheckForLongPress.run(View.java:20260)
E/AndroidRuntime( 6991):    at android.os.Handler.handleCallback(Handler.java:739)
E/AndroidRuntime( 6991):    at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 6991):    at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime( 6991):    at android.app.ActivityThread.main(ActivityThread.java:5597)
E/AndroidRuntime( 6991):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 6991):    at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 6991):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:984)
E/AndroidRuntime( 6991):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
E/AndroidRuntime( 6991): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 6991):    at java.lang.reflect.Constructor.newInstance(Native Method)
E/AndroidRuntime( 6991):    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
E/AndroidRuntime( 6991):    at android.view.LayoutInflater.createView(LayoutInflater.java:611)
E/AndroidRuntime( 6991):    ... 29 more
E/AndroidRuntime( 6991): Caused by: java.lang.RuntimeException: Failed to resolve attribute at index 3
E/AndroidRuntime( 6991):    at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
E/AndroidRuntime( 6991):    at android.support.v7.widget.TintTypedArray.getDrawable(TintTypedArray.java:63)
E/AndroidRuntime( 6991):    at android.support.v7.widget.ActionBarContextView.<init>(ActionBarContextView.java:65)
E/AndroidRuntime( 6991):    at android.support.v7.widget.ActionBarContextView.<init>(ActionBarContextView.java:57)
E/AndroidRuntime( 6991):    ... 32 more

I have added a dependency on recyclerview-v7, appcompat-v7 and support-v4.

I have tried all the suggestions given in questions like this, this and this but nothing worked for me. I tried changing android.widget.EditText to android.support.v7.widget.AppCompatEditText. I tried tinkering with versions of android.support dependencies.

It started crashing all of a sudden. I have been trying to fix it for so long, maybe I need some fresh eyes on it. Please help me out and let me know if more info is required.

3 Answers3

1

First update your gradle :

implementation 'com.android.support:appcompat-v7:"YOUR_SDK_VERSION"'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:"YOUR_SDK_VERSION"'
implementation 'com.android.support:support-v13:"YOUR_SDK_VERSION"'
implementation 'com.android.support:design:"YOUR_SDK_VERSION"'
implementation 'com.android.support:recyclerview-v7:"YOUR_SDK_VERSION"'
implementation 'com.android.support:cardview-v7:"YOUR_SDK_VERSION"'

then use this code :

      <android.support.v7.widget.AppCompatEditText
        android:id="@+id/id2"
        style="@style/myStyle2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="32dp"
        android:layout_marginRight="32dp"
        android:background="@drawable/custom_edittext"
        android:ems="10"
        android:gravity="top"
        android:hint="@string/default_hint"
        android:inputType="textMultiLine"
        android:minLines="6"
        android:paddingBottom="17dp"
        android:paddingLeft="19dp"
        android:paddingRight="19dp"
        android:paddingTop="17dp" />

if still you have same error try this :

  <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat"> // change theme AppTheme to Theme.AppCompat

reference link : click me...!!!

you can do also like this : click me

Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30
0

This should be work for you.hope it will work for you I suggest use

Khalid Saeed
  • 131
  • 2
  • 8
0

I solved this by adding updated cardview and appcompat on the app/build.gradle

dependencies {
    ...
    implementation 'com.android.support:appcompat-v7:23.4.0'    
    implementation 'com.android.support:cardview-v7:23.4.0'
    implementation 'com.android.support:recyclerview-v7:23.4.0'
    }

Then rebuild the project

Gayathri
  • 249
  • 3
  • 13