当编辑文本中的文字发生变化时,应用会崩溃

时间:2018-01-21 17:00:39

标签: java android

我正在尝试使用edittext1减去edittext2将文本设置为edittext字段。

edittext3 = edittext1 - edittext2

然而,当我从edittext2中删除一个整数时,它会崩溃。

EG。通过删除" 0"来自" 80"应用程序崩溃即使是" 8"留在编辑文本上。

任何帮助或建议?

eactualQuantity.addTextChangedListener(new TextWatcher(){

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            //ebalance.setText((Integer.valueOf(emaximumQuantity.getText().toString())-Integer.valueOf(eactualQuantity.getText().toString())));
            if(s.toString().trim().length()>0){
                String a = emaximumQuantity.getText().toString();
                int aint = Integer.parseInt(a);
                String b = eactualQuantity.getText().toString();
                int bint = Integer.parseInt(b);


                int c = (aint - bint);

                ebalance.setText(c);
            }


        }
    });

下面是logcat

  

致命的例外:主要                                                                              处理:nsl.nsl_material_movement,PID:11195                                                                              android.content.res.Resources $ NotFoundException:字符串资源ID#0xc0                                                                                  在android.content.res.Resources.getText(Resources.java:338)                                                                                  在android.widget.TextView.setText(TextView.java:5494)                                                                                  在nsl.nsl_material_movement.UpdateActivity $ 1.afterTextChanged(UpdateActivity.java:123)                                                                                  在android.widget.TextView.sendAfterTextChanged(TextView.java:9375)                                                                                  在android.widget.TextView $ ChangeWatcher.afterTextChanged(TextView.java:11917)                                                                                  在android.text.SpannableStringBuilder.sendAfterTextChanged(SpannableStringBuilder.java:1262)                                                                                  在android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:574)                                                                                  在android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:229)                                                                                  在android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:227)                                                                                  在android.text.method.BaseKeyListener.backspaceOrForwardDelete(BaseKeyListener.java:370)                                                                                  在android.text.method.BaseKeyListener.backspace(BaseKeyListener.java:71)                                                                                  在android.text.method.BaseKeyListener.onKeyDown(BaseKeyListener.java:479)                                                                                  在android.text.method.NumberKeyListener.onKeyDown(NumberKeyListener.java:148)                                                                                  在android.widget.TextView.doKeyDown(TextView.java:7316)                                                                                  在android.widget.TextView.onKeyDown(TextView.java:7093)                                                                                  在android.view.KeyEvent.dispatch(KeyEvent.java:2688)                                                                                  在android.view.View.dispatchKeyEvent(View.java:11658)                                                                                  在android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1827)                                                                                  在android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1827)                                                                                  在android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1827)                                                                                  在android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1827)                                                                                  在android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1827)                                                                                  在android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1827)                                                                                  在com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:437)                                                                                  在com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1818)                                                                                  在android.app.Activity.dispatchKeyEvent(Activity.java:3252)                                                                                  在android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:540)                                                                                  在android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:58)                                                                                  在android.support.v7.app.AppCompatDelegateImplBase $ AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:317)                                                                                  在com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:351)                                                                                  在android.view.ViewRootImpl $ ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:4714)                                                                                  在android.view.ViewRootImpl $ ViewPostImeInputStage.onProcess(ViewRootImpl.java:4586)                                                                                  在android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:4128)                                                                                  在android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:4181)                                                                                  在android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:4147)                                                                                  在android.view.ViewRootImpl $ AsyncInputStage.forward(ViewRootImpl.java:4274)                                                                                  在android.view.ViewRootImpl $ InputStage.apply(ViewRootImpl.java:4155)                                                                                  在android.view.ViewRootImpl $ AsyncInputStage.apply(ViewRootImpl.java:4331)                                                                                  在android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:4128)                                                                                  在android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:4181)                                                                                  在android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:4147)                                                                                  在android.view.ViewRootImpl $ InputStage.apply(ViewRootImpl.java:4155)                                                                                  在android.view.ViewRootImpl $ InputStage.deliver(ViewRootImpl.java:4128)                                                                                  在android.view.ViewRootImpl $ InputStage.onDeliverToNext(ViewRootImpl.java:4181)                                                                                  在android.view.ViewRootImpl $ InputStage.forward(ViewRootImpl.java:4147)                                                                                  在android.view.ViewRootImpl $ AsyncInputStage.forward(ViewRootImpl.java:4307)                                                                                  在android.view.ViewRootImpl $ ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:4468)                                                                                  在android.view.inputmethod.InputMethodManager $ PendingEvent.run(InputMethodManager.java:2435)                                                                                  在android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1998)   01-21 16:52:12.129 11195-11195 / nsl.nsl_material_movement E / AndroidRuntime:at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1989)                                                                                  在android.view.inputmethod.InputMethodManager $ ImeInputEventSender.onInputEventFinished(InputMethodManager.java:2412)                                                                                  在android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)                                                                                  在android.os.MessageQueue.nativePollOnce(本机方法)                                                                                  在android.os.MessageQueue.next(MessageQueue.java:325)                                                                                  在android.os.Looper.loop(Looper.java:142)                                                                                  在android.app.ActivityThread.main(ActivityThread.java:6541)                                                                                  at java.lang.reflect.Method.invoke(Native Method)                                                                                  在com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:240)                                                                                  在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

1 个答案:

答案 0 :(得分:1)

您无法将int设置为textview。它必须是这样的字符串

ebalance.setText(Integer.toString(c));