Programmers learn & share
0 votes

Problem :

While executing Android code getting below error 
java.lang.illegalstateexception could not execute method of the activity
by (6.9k points)   | 61 views

1 Answer

0 votes

Solution :

Bellow line is throwing an Null Pointer Exception, producing an IllegalStateException in the exception chain:

int stopPortRange = Integer.parseInt(stopPort.getText().toString());

As you don't initialize stopPort in your onCreate method. 

stopPort = (EditText) findViewById(;

The statement

EditText stopPort;

simply declares the variable which is null by default. Only instances that have been instantiated can have their methods invoked.

Further Readings:

by (36.1k points)  
edited by
2,187 questions
2,514 answers
241 users