I had the same problem. The problem is that communication with endpoints should NOT be done on ui / main thread. The easiest way is to create a simple ASyncTask, for example, for example:
private class InsertTask extends AsyncTask<Void, Void, Void> { Exception exceptionThrown = null; TargetEndpoint targetEndpoint; Target target; public InsertMessageTask(Activity activity, TargetEndpoint targetEndpoint, Target target) { this.messageEndpoint= messageEndpoint; this.target= target; } @Override protected Void doInBackground(Void... params) { try { targetEndpoint.insertTarget(target).execute(); } catch (IOException e) { exceptionThrown = e; } return null; } protected void onPostExecute(Void arg) { TheActivity.this.runOnUiThread(new Runnable() { @Override public void run() { if (exceptionThrown == null) Toast.makeText(TheActivity.this, "Success!", Toast.LENGTH_LONG).show(); else Toast.makeText(TheActivity.this, "Error occured: '" + exceptionThrown.getMessage(), Toast.LENGTH_LONG).show(); } }); } }
I agree that the error message may be more indicated, but it has a reason. You do not want to run expensive methods on the ui thread, as this can reduce its performance.
source share