2017-04-12 55 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。你回答了我的问题。 –

相关问题