"getText" 语法无效并且显示错误

"getText" syntax is not working and it's showing error

“getText”语法无效,显示错误。

    @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

 }
}

现在在您的 Activity 中调用异步任务时执行此操作

// Its inside the Activity Class 
MyAsyncTask asd = new MyAsyncTask(username.getText().toString(),password.getText().toString());

asd.execute("");

在 activity

中调用 AsyncTask 本身时传递 EditText 的值