我收到错误AsyncTask不会覆盖超类的方法?

时间:2016-12-27 07:58:36

标签: java android asynchronous android-asynctask override

它说Async不会覆盖超类中的任何方法。 这是一个来自tutorialspoint网站的示例。 这似乎不起作用。请帮忙。 提前致谢。 *编辑:我已经上传了完整的java文件。

public class SigninActivity extends AsyncTask{

        private Context context;
        private TextView statusField,userField;

        public SigninActivity(Context context,TextView statusField,TextView userField) {
            this.context = context;
            this.statusField = statusField;
            this.userField = userField;
    }

        protected void onPreExecute(){
        }


        @Override
        protected String doInBackground(String... arg0) {
            try{
                String username = (String)arg0[0];
                String password = (String)arg0[1];

                String link="http://127.0.0.1/login.php";
                String data  = URLEncoder.encode("username", "UTF-8") + "=" +
                        URLEncoder.encode(username, "UTF-8");
                data += "&" + URLEncoder.encode("password", "UTF-8") + "=" +
                        URLEncoder.encode(password, "UTF-8");

                URL url = new URL(link);
                URLConnection conn = url.openConnection();

                conn.setDoOutput(true);
                OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

                wr.write( data );
                wr.flush();

                BufferedReader reader = new BufferedReader(new
                        InputStreamReader(conn.getInputStream()));

                StringBuilder sb = new StringBuilder();
                String line = null;

                // Read Server Response
                while((line = reader.readLine()) != null) {
                    sb.append(line);
                    break;
                }

                return (sb.toString());
            }
            catch(Exception e){
               return (new String("Exception: " + e.getMessage()));
            }
        }
    @Override
        protected void onPostExecute(String result){
            this.statusField.setText("Login Successful");
            this.userField.setText(result);
        }
    }

1 个答案:

答案 0 :(得分:0)

 public class SigninActivity extends AsyncTask<String, String, String>

使用上面的代码,它将完成工作