我正在尝试编写一个返回我的计算机 MAC 地址字符串的静态方法(该函数本身可以在此处找到:http ://www.mkyong.com/java/how-to-get-mac-address-in-java /)。我return
在静态函数方面遇到问题。我得到的错误是missing return statement
. 我该如何补救?
static String returnMacAddress(){
InetAddress ip;
try{
ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
System.out.print("Current MAC address: ");
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < mac.length; i++){
stringBuilder.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
}
return stringBuilder.toString();
}catch(UnknownHostException e){
e.printStackTrace();
} catch(SocketException e){
e.printStackTrace();
}
}