私はアンドロイドアプリの開発には初めてです。最近、Ipifyに基づいて公開IPを表示できるアプリケーションを作成しています。これまでのところ、私はすでに:Androidの報告されていない例外IOExceptionエラー
- 必要なjarファイルをダウンロードし、LIBSのフォルダの中に入れ
- 私はまた、Gradleの
- 内のファイルをコンパイルし、私はそれがどのよう
私のクラスに必要なクラスをインポートします
import org.ipify.Ipify;
public class HelloIP {
public static void main(String[] args) throws IOException {
System.out.println(Ipify.getPublicIp());
}
}
私は次のメソッドを別のものから呼び出すように書いていますクラス:私は、コードを修正して、次のtryおよびcatchを使用しようとしましたが、それでも同じだ
Error:(52, 43) error: unreported exception IOException; must be caught or declared to be thrown
:
public static String getPublicIp() throws IOException{
String ip = Ipify.getPublicIp();
return ip;
}
別のクラス
//Get wifi
getWifiName wifiInfo = new getWifiName();
String myIP = wifiInfo.getPublicIp();
しかし、私は得続けますエラー。
public static String getPublicIp() throws IOException{
String myip = Ipify.getPublicIp();
try{
return myip;
}
catch (IOException e){
System.out.println("General I/O exception: " + e.getMessage());
e.printStackTrace();
}
}
イムキャッチとスロー例外ではあまりにも良いし、すでにアイデアもうそれはdidnの場合、このerror..TT
*と、次のtryおよびcatchを使用* ... aroudを試してみてください彼らはすべて
Exception
延びていることや事実を使用して、明白な 'return' statment ...魅力的な – Selvin
不受任の理由は何ですか? – xenteros