android 为什么第二次点击edittext字段会导致应用程序错误?

kd3sttzy  于 2023-04-28  发布在  Android
关注(0)|答案(1)|浏览(225)

我有一个获取数字的edittext字段。当字段清除时,我可以随意触摸它。如果出现一个字符,我关闭键盘,第二次点击edittext,应用程序将获得一个get运行时。
我试图找到一些方法或任何东西来帮助我在Android文档有关EditText,但我没有找到它。
这是我的代码
java

package com.example.aplikacja_testowa;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class CallSettings extends AppCompatActivity {
    private TextView textView;
    private EditText editText;
    private Button saveButton;

    public static final String SHARED_PREFS = "sharedPrefs";
    public static final String TEXT = "text";
    //public static final

    private String text;

    ////////////////
    int dem=0;
    int them;
    int selectTheme = 2;
    ////////////////

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        them=SmsSettings.loadData(CallSettings.this, "style.txt", null, dem);
        selectTheme = them;
        Log.i("TAG", "onCreate selectTheme: "+selectTheme);
        FontSettings.setDynamicTheme(CallSettings.this, selectTheme);

        setContentView(R.layout.activity_call_settings);
        textView = findViewById(R.id.callInstruction);
        editText = findViewById(R.id.textPhoneNumber);
        saveButton = findViewById(R.id.save_button);
    }

    public void savePhoneNumber(View v){
        SmsSettings.saveData(this, "callnumber.txt", editText, 0);
        Toast.makeText(this, R.string.number_saved, Toast.LENGTH_SHORT).show();
    }
}

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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".CallSettings">

    <TextView
        android:id="@+id/callInstruction"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/after_ent_the_num"
        app:layout_constraintBottom_toTopOf="@+id/textPhoneNumber"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/textPhoneNumber"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/inp_ph_num"
        android:inputType="phone"
        android:minHeight="48dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/save_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:onClick="savePhoneNumber"
        android:text="@string/save_sett"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textPhoneNumber" />
</androidx.constraintlayout.widget.ConstraintLayout>
E/InputEventReceiver: Exception dispatching input event.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: android.content.res.Resources$NotFoundException: Resource ID #0x0
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
        at android.content.res.Resources.getDrawable(Resources.java:766)
        at android.content.Context.getDrawable(Context.java:525)
        at android.widget.Editor$InsertionPointCursorController.getHandle(Editor.java:5070)
        at android.widget.Editor$InsertionPointCursorController.show(Editor.java:5049)
        at android.widget.Editor.onTouchUpEvent(Editor.java:2136)
        at android.widget.TextView.onTouchEvent(TextView.java:8510)
        at android.view.View.dispatchTouchEvent(View.java:9943)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:411)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1810)
        at android.app.Activity.dispatchTouchEvent(Activity.java:3061)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:373)
        at android.view.View.dispatchPointerEvent(View.java:10163)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4434)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4302)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3902)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3868)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3995)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3876)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4052)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3902)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3868)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3876)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6210)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6184)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6145)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6313)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:323)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.aplikacja_testowa, PID: 14480
    android.content.res.Resources$NotFoundException: Resource ID #0x0
        at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
        at android.content.res.Resources.getDrawable(Resources.java:766)
        at android.content.Context.getDrawable(Context.java:525)
        at android.widget.Editor$InsertionPointCursorController.getHandle(Editor.java:5070)
        at android.widget.Editor$InsertionPointCursorController.show(Editor.java:5049)
        at android.widget.Editor.onTouchUpEvent(Editor.java:2136)
        at android.widget.TextView.onTouchEvent(TextView.java:8510)
        at android.view.View.dispatchTouchEvent(View.java:9943)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2669)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2358)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:411)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1810)
        at android.app.Activity.dispatchTouchEvent(Activity.java:3061)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:373)
        at android.view.View.dispatchPointerEvent(View.java:10163)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4434)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4302)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3902)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3868)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3995)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3876)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4052)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3902)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3868)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3876)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3849)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6210)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6184)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6145)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6313)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:323)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
1yjd4xko

1yjd4xko1#

显然,无论FontSettings.setDynamicTheme()改变了什么主题细节,它最终都会让你的小部件处于无效或不完整的状态,或者样式引用了不存在的资源。
我的猜测是,如果EditText中没有输入内容,它为什么会起作用,因为如果没有内容,小部件就不需要绘制它的一些元素。所以你可以让你的空EditText多次聚焦,不会发生什么不好的事情,但是如果有任何内容和样式,即引用缺少的资源。我猜FontSettings是外部项目,所以我会检查更新的拳头,然后我会检查它试图应用的样式。

相关问题