0

I've been trying to run this app but it throws the same error every time, I've tried everything I could. I would really like an expert's help over this. This is a simple app to calculate and play with numbers in some manner idk if I should provide the .xml files too but I definitely will if they are needed.

   public class MainActivity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            final EditText e1=(EditText) findViewById(R.id.name);
            final EditText e2=(EditText)findViewById(R.id.date);
            final EditText e3=(EditText)findViewById(R.id.month);
            final EditText e4=(EditText)findViewById(R.id.year);
            Button b=(Button) findViewById(R.id.button);

            char[] n = e1.getText().toString().toCharArray();
            int date = Integer.parseInt(e2.toString());
            int month = Integer.parseInt(e3.toString());
            int year = Integer.parseInt(e4.toString());
            int nn = 0;
            int driver=date, conductor=date+month+year;
            int temp,k=0;


    //EditText Jumping Module-------------------------------


        e2.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {
                int tl = e2.getText().length();

                if (tl >= 2) {
                    e3.requestFocus();
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
        e3.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {
                int lt = e3.getText().length();

                if (lt >= 2) {
                    e4.requestFocus();
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });

I don't think the rest of the code has any problem is the starting section so I've provided that above. Thank you

Saveen
  • 4,120
  • 14
  • 38
  • 41

1 Answers1

0

jhamon's comment is spot on. Your EditTexts are most likely empty, the user did not input any value yet but you try to get that value. However, since you included no logs and no xml (at the time i am writing this) i am going to assume that the EditTexts have some default value that you assigned in the xml and that is the value you want to get at this point.

For EditText e1 you get the text like this :

e1.getText().toString()

For the rest of the EditTexts you are missing the getText(). You simply say:

int date = Integer.parseInt(e2.toString());
int month = Integer.parseInt(e3.toString());
int year = Integer.parseInt(e4.toString());

So add the getText().

But please add the log output and you xml. It would really help us help you! ;)