@Override
protected Void doInBackground(String... params) {
String type = params[0];
String url= "http://10.0.2.2/login.php" ;
if(type.equals("Singin")) {
try {
URL Singin_url = new URL(url);
//Cannot not resolve method 'openConnection()'
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return null;
}
为什么不让它让OpenConnection? 我不能前进,因为它说'连接'没有初始化
答案 0 :(得分:1)
您需要在openConnection()
对象URL
上调用Singin_url
方法。您在String
对象上调用它。
@Override
protected Void doInBackground(String... params)
{
String type = params[0];
String url= "http://10.0.2.2/login.php" ;
if(type.equals("Singin"))
{
try {
URL Singin_url = new URL(url);
HttpURLConnection connection = (HttpURLConnection)Singin_url.openConnection();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
return null;
}
此外,您的变量名称第一个字符应为小写,例如signInUrl
。