Java / Android:AsyncTask类型的参数数量不正确

时间:2011-09-21 22:19:36

标签: java android compiler-errors android-asynctask

我认为这段代码有问题。有人可以检查一下代码中是否有错误吗?

        ImageView userPicture = (ImageView) findViewById(R.id.userPicture);

    private synchronized void downloadAvatar(){
        AsyncTask <Bitmap> task = new AsyncTask <Bitmap> (){

            @Override
            public void onPreExecute() {
                //Do nothing
            }

            @Override
            public Bitmap doInBackground() {
                URL fbAvatarUrl = null;
                Bitmap fbAvatarBitmap = null;
                try {
                    fbAvatarUrl = new URL("http://graph.facebook.com/"+userID+"/picture");
                    fbAvatarBitmap = BitmapFactory.decodeStream(fbAvatarUrl.openConnection().getInputStream());
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return fbAvatarBitmap;
            }

            @Override
            public void taskComplete(Bitmap result) {
                fbUserAvatar.setImageBitmap(result);
            }

        };
        task.execute();
    }

我在使用此代码的行上收到错误:

AsyncTask <Bitmap> task = new AsyncTask <Bitmap> ()

错误消息是:

  

AsyncTask类型的参数数量不正确;它不能用参数

参数化

1 个答案:

答案 0 :(得分:4)

AsyncTask有三个参数:参数,进度和结果。你的情况应该是AsyncTask< Bitmap, Void, Void >; doInBackground应该Bitmap... args