I am newbie in android so i am not famalier to all errors here is the error that I am getting (Unreachable catch block for JSONException. This exception is never thrown from the try statement body) in my catch clause while json parsing. Can anyone please tell what shall i do.Thanks here my code:
if (usernameEditText == null || passwordEditText == null)
{
Toast.makeText(HelloAndroid.this, "Please enter your username & password",Toast.LENGTH_SHORT).show();
}
else
{
// display the username and the password in string format
try
{
showBusyCursor(true);
progress = ProgressDialog.show(this,"Please wait...", "Login in process", true);
Log.i(DEB_TAG, "Username: " + sUserName + "nPassword: " + sPassword);
Log.i(DEB_TAG, "Requesting to "+address);
JSONObject json = RestJsonClient.connect(address);
}
catch (JSONException e)
{
e.printStackTrace();
showBusyCursor(false);
}
}
Your error means, that
1. either the code in your
tryblock never throws anJSONException,2. or the
JSONExceptionis caught before thecatch (JSONException e)block, so yourtry-catchblock might look like:Here the
catch (Exception e)block is called before theJSONException, and sinceJSONExceptionextends theExceptionclass, it won’t be entered ever.In this case you should change the order of your catch blocks, and will be able to handle the two exception types differently.