この問題の理由openConnectionは、クラス コンストラクター (URL) とメソッド ( ..) が例外 ( で定義) をスローし、signatures必要な手順を実行することをコンパイラーが通知しているためです。
次の 2 つのオプションがあります。
Throwチェックされた例外はメインメソッドからのものです。
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.google.com");
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
System.out.println("Response code is " +
httpCon.getResponseCode());
}
また
Exceptionを使用してそれをキャッチtry catch block.
public static void main(String[] args) {
URL url;
HttpURLConnection httpCon;
try {
url = new URL("http://www.google.com");
httpCon = (HttpURLConnection) url.openConnection();
System.out.println("Response code is " + httpCon.getResponseCode());
} catch (IOException e) {
e.printStackTrace();
}
}