我想知道是什么让我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 :(得分:0)
你需要捕获IOException
... finally {
try {
urlConnection.disconnect();
} catch (IOException ioex) { }