我是韩国的安卓开发者。目前,我做了一个关于socket的项目。但是,我有一些问题,所以我进入了这个网站。看!
class PingCheckThread implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
while(!Thread.currentThread().isInterrupted()){
try {
if(device != null){
for(int i = 0; i < device.size(); i++){
String info = (String) device.get(i);
int first = info.indexOf(":");
int last = info.lastIndexOf(":");
String ip = info.substring(first, last);
InetAddress targetIp =
Inet4Address.getByAddress(ip.getBytes()); ///< error!!
if(targetIp.isReachable(60000)){
Log.v(TAG, "Connection Ok");
}else{
Log.v(TAG, "Connection Fail");
}
}
}
Thread.sleep(60000);
} catch (Exception e) {
// TODO Auto-generated catch block
Log.v(TAG, e.getMessage());
}
}
}
}
日志>
08-26 11:27:34.124: W/dalvikvm(3612): threadid=13: thread exiting with uncaught exception (group=0x2c43b930)
08-26 11:27:35.464: E/AndroidRuntime(3612): FATAL EXCEPTION: Thread-216
08-26 11:27:35.464: E/AndroidRuntime(3612): java.lang.NullPointerException
08-26 11:27:35.464: E/AndroidRuntime(3612): at com.skb.sportscompanion.tv.SportsCompanionTV$PingCheckThread.run(SportsCompanionTV.java:206)
08-26 11:27:35.464: E/AndroidRuntime(3612): at java.lang.Thread.run(Thread.java:856)
为什么 inetAddress 有空指针异常?它出现了 InetAddress.getByName、InetAddress.geyByAddress。我想知道这个错误。我已经写了使用许可。android:name="android.permission.INTERNET" android:name="android.permission.ACCESS_NETWORK_STATE"