代碼: - try塊不執行,如果我擴展Asynctask應用程序 崩潰,並且如果我不擴展Asynctask那麼catch(Exception e)會給我一個錯誤消息 - 「android.os.NetworkOnMainThradException」。try塊不執行
嘗試{
HttpURLConnection con = (HttpURLConnection) new URL("http://apis.hofficedemo1.ondemandcrm.co/AppRequestAPI").openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.connect();
con.getOutputStream().write(("txt_username=" + txt_username).getBytes());
con.getOutputStream().write(("txt_password=" + txt_password).getBytes());
con.getOutputStream().write(("appMode=" + appMode).getBytes());
con.getOutputStream().flush();
//System.out.println(txt_username+" "+txt_password+" "+appMode);
InputStream is = con.getInputStream();
byte[] b = new byte[1024];
while (is.read(b) != -1) {
System.out.println(Arrays.toString(b));
}
con.disconnect();
} catch (IOException e) {
Log.d("IOException", "Some error");
}
catch (Exception e){
e.printStackTrace();
}
請提catch塊異常 寫e.printStackTrace(),看看有沒有什麼異常,並張貼在這裏 –
我不知道什麼是與try塊的問題。我試過各種方法,並明白這是有問題的HttpURLConnection –
添加e.printStackTrace()在catch塊中看看有什麼問題在嘗試塊 –