Add two edittext while typing, error Resources $ NotFoundException

0
Tara = (EditText)findViewById(R.id.txtTaras);
        Tara.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) {
                if(Tara.getText().length() > 0 && Peso.getText().length() >0) {
                    double rPeso = Double.parseDouble((Peso.getText().toString()));
                    double rTara = Double.parseDouble((Tara.getText().toString()));
                    double resta = rPeso - rTara;
                    Preal.setText((int) resta);
                }else{
                    Preal.setText("");
                }

            }
        });

but it marks me wrong,

  

android.content.res.Resources $ NotFoundException: Resource ID # 0x

someone to help me solve it.

  

Error!   

    
asked by DoubleM 31.08.2017 в 19:52
source

2 answers

3

the setText() method has an overload setText(int resource) that receives an int that is the id of a resource type String and clearly the result of the subtraction does not is the id of a string resource. Convert the value int to String to assign the text to the TextView.

Change

 Preal.setText((int) resta);

To this:

 int restaInt = (int) resta;
 Preal.setText(restaInt.toString());
    
answered by 31.08.2017 в 19:59
1

This I have seen it asked in the site but I did not find the question,

  

android.content.res.Resources $ NotFoundException: Resource ID # 0x

The problem is derived when trying to define an integer using the method setText () , the view, in this case the TextView , tries to find an element with id defined in R.java (a resource identifier) which in this case does not exist, for this reason you have to be sure to define in setText () a value type% % co:

// Preal.setText((int) resta);
Preal.setText(String.valueOf(resta));

Update:

I found the question, however the answer marked as correct, does not indicate why the error is obtained:

This method does not work to show () in an Android app to change the text of a TextView

    
answered by 31.08.2017 в 20:43