public int coderesult (String urlstring) throws Exception {
URL url = new URL(urlstring);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
//System.out.println("Response code is " + httpCon.getResponseCode());
int mycode = httpCon.getResponseCode();
return mycode;
}
public int displaycode() {
int dispcode = 0;
try {
dispcode = coderesult(myurl);
}
catch (MalformedURLException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally {
}
return dispcode;
}
Android Studio在「dispcode = coderesult(myurl);」中顯示錯誤「 :「未處理的異常:java.lang.Exception的」未處理的異常如果調用HttpURLConnection
後全堆棧跟蹤和具體。你用這個'httpCon.getResponseCode()'得到了什麼? –