Note that there are some explanatory texts on larger screens.

plurals
  1. POIllegalStateException when using drawable XML
    text
    copied!<p>When using an ImageButton with this XML: </p> <p>and the following drawable XML:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:drawable="@drawable/bruin_s1" android:state_pressed="false" /&gt; &lt;item android:drawable="@drawable/bruin_s2" android:state_pressed="true" /&gt; &lt;item android:drawable="@drawable/bruin_s1" android:state_focused="false" /&gt; &lt;item android:drawable="@drawable/bruin_s2" android:state_focused="true" /&gt; &lt;/selector&gt; </code></pre> <p>It will crash when I click that button with this exception:</p> <pre><code>06-17 10:18:23.028: ERROR/AndroidRuntime(290): Uncaught handler: thread main exiting due to uncaught exception 06-17 10:18:23.048: ERROR/AndroidRuntime(290): java.lang.IllegalStateException: Could not execute method of the activity 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.View$1.onClick(View.java:2031) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.View.performClick(View.java:2364) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.View.onTouchEvent(View.java:4179) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.View.dispatchTouchEvent(View.java:3709) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.app.Activity.dispatchTouchEvent(Activity.java:2061) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.os.Handler.dispatchMessage(Handler.java:99) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.os.Looper.loop(Looper.java:123) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.app.ActivityThread.main(ActivityThread.java:4363) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at java.lang.reflect.Method.invokeNative(Native Method) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at java.lang.reflect.Method.invoke(Method.java:521) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at dalvik.system.NativeStart.main(Native Method) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): Caused by: java.lang.reflect.InvocationTargetException 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at nl.ivaldi.borre.Drawing.onColorClick(Drawing.java:135) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at java.lang.reflect.Method.invokeNative(Native Method) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at java.lang.reflect.Method.invoke(Method.java:521) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): at android.view.View$1.onClick(View.java:2026) 06-17 10:18:23.048: ERROR/AndroidRuntime(290): ... 20 more 06-17 10:18:23.048: ERROR/AndroidRuntime(290): Caused by: java.lang.ClassCastException: android.graphics.drawable.StateListDrawable 06-17 10:18:23.048: ERROR/AndroidRuntime(290): ... 24 more </code></pre> <p>However, when I change the drawable to one of the images (i.e. bruin_s1) it will work just fine. What's wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload