Java &引用;getText";语法不起作用,它';显示错误
“getText”语法不起作用,显示错误Java &引用;getText";语法不起作用,它';显示错误,java,android,android-asynctask,Java,Android,Android Asynctask,“getText”语法不起作用,显示错误 @Override protected String doInBackground(String... params) { String usernam = username.getText().toString(); String passwordd = password.getText().toString(); if(usernam.trim().equals("&q
@Override
protected String doInBackground(String... params)
{
String usernam = username.getText().toString();
String passwordd = password.getText().toString();
if(usernam.trim().equals("")|| passwordd.trim().equals(""))
{
z = "Please enter Username and Password";
}
else
{
try
{
con = connectionclass(un, pass, db, ip);
if (con == null)
{
z = "Check Tour Internet Access!";
}
else
{
String query = "select * from login where user_name= '" + usernam.toString() + "' and pass_word = ' " + passwordd.toString();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
if(rs.next())
{
z = "Login successful";
isSuccess = true;
con.close();
}
else
{
z = "Invalid Credentials";
isSuccess = false;
}
}
}
catch (Exception ex)
{
isSuccess = false;
z = ex.getMessage();
}
}
return z;
}
我无法得到答案,预期的答案是,应该能够检索用户名、密码并将其与我们输入的用户名密码匹配,但现在我无法同时匹配这两个
private class MyAsyncTask extends AsyncTask<String, Void, String> {
private String username="";
private String password="";
public MyAsyncTask(String user, String pass)
{
this.username = user;
this.password = pass;
}
protected void onPreExecute() {
}
protected Bitmap doInBackground(String... strings) {
// Some long-running task like downloading an image.
// No UI related work here.. or else it will crash
}
protected void onPostExecute(Bitmap result) {
// This method is executed in the UIThread
// with access to the result of the long running task
}
}
在活动中调用AsyncTask本身时传递EditText的值什么不起作用?你期待什么?相反会发生什么?请解释。顺便说一句,在创建SQL查询时不要使用连接,否则您将引入。改为使用PreparedStatement.String usernam=username.getText().toString();字符串passwordd=password.getText().toString();这两行显示了错误您得到了什么错误?无法解析方法。getText()error@Paul P Jobyyou应该将该方法与您在活动中使用的textView名称一起使用。您应该使用findViewById(R.id.nameoftextview)在主活动中声明用户名和密码的textView方法如果您认为问题在于@Tharminian and SivanesAnsorry login=(按钮)findViewById(R.id.btnlogin),请批准答案;用户名=(EditText)findViewById(R.id.editText2);密码=(EditText)findViewById(R.id.EditText);progressBar=(progressBar)findViewById(R.id.progressBar);你是说这部分吗
// Its inside the Activity Class
MyAsyncTask asd = new MyAsyncTask(username.getText().toString(),password.getText().toString());
asd.execute("");