【发布时间】:2016-07-13 20:03:37
【问题描述】:
以下代码来自this答案
try {
// get all the interfaces
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
//find network interface wlan0
for (NetworkInterface networkInterface : all) {
if (!networkInterface.getName().equalsIgnoreCase("wlan0")) continue;
//get the hardware address (MAC) of the interface
byte[] macBytes = networkInterface.getHardwareAddress();
if (macBytes == null) {
return "";
}
StringBuilder res1 = new StringBuilder();
for (byte b : macBytes) {
//gets the last byte of b
res1.append(Integer.toHexString(b & 0xFF) + ":");
}
if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch (Exception ex) {
ex.printStackTrace();
}
我在这两行出现错误Cannot return a value with void result type:return ""; 和return res1.toString(); 我将代码放入public void onStart() 如何解决这个问题,你能告诉我这个问题的原因吗?
【问题讨论】:
-
如果 try 块抛出异常会发生什么?回报在哪里?
-
我的猜测是,你在 void 方法中有该代码,而 void 方法不返回任何内容
标签: java android android-studio