2017-04-12 149 views
0

我想知道是什麼讓我的url.openConnection出錯。 錯誤是:爲什麼我在url.openConnection()下變爲紅色下劃線()

未處理的異常

這裏是代碼:

switch (v.getId()){ 
    case R.id.loginbtn: 
     String link; 
     String username = uname.getText().toString(); 
     String password = upass.getText().toString(); 
     HttpURLConnection urlConnection = null; 

     try { 
      String u = "http://127.0.0.1/android/login.php"; 
      URL url = new URL(u); 
      String urlParams = "username="+username+"&password"+password; 

      urlConnection = (HttpURLConnection) url.openConnection(); 

     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
     } finally { 
      urlConnection.disconnect(); 
     } 
+0

讓IDE自動完成錯誤修復 –

回答

0

你需要捕捉IOException異常

... finally { 
try { 
urlConnection.disconnect(); 
} catch (IOException ioex) { } 
+0

謝謝@Michael Meyer。你回答了我的問題。 –

相關問題