Application crashes when EditText is touched

When the EditText view is empty, I can touch it and start entering data. But when I touch it while some data is typed, application crashes, giving following stack trace:

    E/InputEventReceiver: Exception dispatching input event.
    D/AndroidRuntime: Shutting down VM
    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.bullscows, PID: 31754
        android.content.res.Resources$NotFoundException: Resource ID #0x0
            at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:293)
            at android.content.res.Resources.getDrawableForDensity(Resources.java:1022)
            at android.content.res.Resources.getDrawable(Resources.java:965)
            at android.content.Context.getDrawable(Context.java:605)
            at android.widget.Editor$InsertionPointCursorController.getHandle(Editor.java:5219)
            at android.widget.Editor$InsertionPointCursorController.show(Editor.java:5198)
            at android.widget.Editor.onTouchUpEvent(Editor.java:2247)
            at android.widget.TextView.onTouchEvent(TextView.java:9809)
            at android.view.View.dispatchTouchEvent(View.java:11891)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3024)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2680)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3024)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2680)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3024)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2680)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3024)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2680)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3024)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2680)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3024)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2680)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3024)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2680)
            at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:449)
            at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1837)
            at android.app.Activity.dispatchTouchEvent(Activity.java:3405)
            at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
            at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:411)
            at android.view.View.dispatchPointerEvent(View.java:12135)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5158)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4968)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4494)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4547)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4513)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4640)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4521)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4697)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4494)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4547)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4513)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4521)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4494)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7096)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7070)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7027)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7226)
            at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:193)
            at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
            at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:182)
            at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:7181)
            at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:7250)
    E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:999)
            at android.view.Choreographer.doCallbacks(Choreographer.java:811)
            at android.view.Choreographer.doFrame(Choreographer.java:733)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:985)
            at android.os.Handler.handleCallback(Handler.java:795)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:166)
            at android.app.ActivityThread.main(ActivityThread.java:6861)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:450)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

I am not sure which code should I provide, because I have several classes and already complicated logic, so I think I should first understand what the problem could really be.

Here is xml code for the EditText:

<EditText
    android:id="@+id/input"
    android:importantForAutofill="no"
    android:textSelectHandle="@null"
    android:visibility="visible"
    android:layout_width="180dp"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentTop="true"
    android:background="@drawable/rounded_field"
    android:inputType="number"
    android:textCursorDrawable="@null"
    android:padding="8dp"
    android:layout_marginTop="12dp"
    android:layout_marginBottom="16dp"
    android:textSize="22sp"
    tools:ignore="LabelFor" />

Answer

The reason android:textSelectHandle="@null" is not desired is because when you click on a point in editable text, a pointer appears. Setting it to @null will prevent it from appearing since there is no such resource corresponding to that parameter, which causes the program to crash. Set it to "@android:color/transparent".

Leave a Reply

Your email address will not be published. Required fields are marked *