String url = "http://xyzcloud.com/xyz/xyz.php";
沒有互聯網接入這個網址我試圖從雲中的數據,如果網絡連接,然後異步任務將執行 我寫了這個方法檢查羯羊互聯網連接與否,在這裏我的移動WLAN網絡時我試圖執行它給例外如何停止在互聯網連接的AsyncTask,但在Android的
public boolean checkOnlineState()
{
boolean val = false;
ConnectivityManager CManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo NInfo = CManager.getActiveNetworkInfo();
if (NInfo != null && NInfo.isConnectedOrConnecting()) {
try {
if (InetAddress.getByName(url).isReachable(10000))
{
// host reachable
val=true;
Log.e("checkOnlineState", "" + val);
}
else
{
// host not reachable
val = false;
Log.e("checkOnlineState", "" + val);
}
} catch (IOException e) {
e.printStackTrace();
}
}
return val;
}
這是例外,我得到 致命異常:主要 過程:com.xyz.xyz,PID:13405 android.os.NetworkOnMainThreadException 在android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1288 ) \t在java.net.InetAddress.lookupHostByName(InetAddress.java:432) \t在java.net.InetAddress.getAllByNameImpl(InetAddress.java:253) \t在java.net.InetAddress.getByName(InetAddress.java: 306) – veeraprasad
手柄插座超時而連接在catch塊 – Raghunandan
超時增加兩個異常之後,它漚甕假 – veeraprasad