[Solved] application crashed with NumberFormatException


The reason you are getting this error is because the EditText is not created on the UI yet.

But, you need the EditText on the screen, along with some valid data before you can call Integer.parseInt.

You need to use some sort of interface, through which you would call Integer.parseInt. I suggest using a button.

If you don’t want to add a button though, use this code:

a.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        int i = Integer.parseInt(a.getText().toString());
        //any operation involving i
        return true;
    }
});

Then, after you type some data into a, long press a, and see the magic!

solved application crashed with NumberFormatException