I'm assuming because you're error is
"Couldn't reach the server"
you are trying to make network calls, which means your code is in a thread of some sort? You cannot touch UI elements from inside the main thread so move:
Toast.makeText(MainActivity.this, "Couldn't reach the server", Toast.LENGTH_LONG).show();
Into the postExecute()
method of an AsyncTask or use a Handler
From the docs
Do not access the Android UI toolkit from outside the UI thread.