1

I have this error in my project this error just in api 19 ( in android 4.4 )

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.noxef.notecap/com.noxef.notecap.NewEnter}: android.view.InflateException: Binary XML file line #26: Error inflating class android.widget.ToggleButton
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
    at android.app.ActivityThread.access$800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
    at dalvik.system.NativeStart.main(Native Method)

Caused by: android.view.InflateException: Binary XML file line #26: Error inflating class android.widget.ToggleButton
    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.noxef.notecap.NewEnter.onCreate(NewEnter.java:28)
    at android.app.Activity.performCreate(Activity.java:5231)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 
    at android.app.ActivityThread.access$800(ActivityThread.java:135) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:136) 
    at android.app.ActivityThread.main(ActivityThread.java:5001) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:515) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
    at dalvik.system.NativeStart.main(Native Method) 

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/visibility_password.xml from drawable resource ID #0x7f0700a6
   at android.content.res.Resources.loadDrawable(Resources.java:2096)
   at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_visibility.xml from drawable resource ID #0x7f07008e
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector

What can I do - have cleaned it already

I searched for the error and found it in this XML code just here in android:background="@drawable/visibility_password":

<ToggleButton
    android:id="@+id/show"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginEnd="8dp"
    android:layout_marginRight="8dp"
    android:layout_weight="0"
    android:background="@drawable/visibility_password"
    android:gravity="center"
    android:textOff=""
    android:textOn="" />

I'm using Vector XML in background not Image.

10
  • Could you post visibility_password drawable please Commented Oct 21, 2018 at 14:16
  • <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="schemas.android.com/apk/res/android"> <item android:state_checked="true" android:drawable="@drawable/ic_visibility" /> <item android:state_checked="false" android:drawable="@drawable/ic_visibility_off" /> </selector> Commented Oct 21, 2018 at 14:17
  • Can you show a picture of hierarchy of android drawables which is found the left mst side in android studio.. Commented Oct 21, 2018 at 14:45
  • I don't understand Commented Oct 21, 2018 at 14:58
  • When you expand the res folder in the left, you get many other folders.. can you send a pic of those folders from Android Studio Commented Oct 21, 2018 at 15:05

3 Answers 3

1

Solution: Try these steps below:

First, Add this line in your ic_visibility.xml and ic_visibility_off.xml

<vector
    ...
    android:tintMode="multiply"
    ...>

    ......
    ......

</vector>

Then, Don't forget to add build.gradle(Module:app) or the approach will not work on old Android versions.

defaultConfig {
    ....
    vectorDrawables.useSupportLibrary = true
    ....
}

Lastly, add this in you activity class, before onCreate():

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

Try it. Hope it helps. Please comment if any doubts.

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

1 Comment

@AflaYoussef Happy To Help. :)
0

visibility_password.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true"
        android:drawable="@drawable/ic_visibility" />

    <item android:state_checked="false"
        android:drawable="@drawable/ic_visibility_off" />
</selector>

Comments

0

Your this file visibility_password.xml must not be in the res/drawable directory.

Set project files as Project view. You might see some other folders like "drawable-v24"

Move your visibility_password.xml file to res/drawable folder.

This will resolve your issue

Comments

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.