EverydayDiesel
Newbie
Hello,
I am trying to invoke an api (or in this example just get the web response from a web server)
I keep getting a general exception.
ex.toString() == android.os.NetworkOnMainThreadExectption
ex.getMessage() == ""
Thanks in advance!
I am trying to invoke an api (or in this example just get the web response from a web server)
Code:
try
{
URL url = new URL("http://mywebsite.com/");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try
{
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
String theString = convertStreamToString(in);
} finally {
urlConnection.disconnect();
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (Exception ex)
{
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle(ex.toString());
alertDialog.setMessage(ex.getMessage());
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
I keep getting a general exception.
ex.toString() == android.os.NetworkOnMainThreadExectption
ex.getMessage() == ""
Thanks in advance!