Android java.lang.IllegalStateException: Could not execute method of the activity
This line is throwing anNPE, producing an IllegalStateException in the exception chain: as you don’t initialize stopPort (or startPort) in your onCreate method. You should have something like: The statement simply declares the variable which is null by default. Only instances that have been instantiated can have their methods invoked.