【问题标题】:Picasso Target Error: method BitmapDrawable is undefined for type new Target()Picasso 目标错误:方法 BitmapDrawable 未定义新 Target() 类型
【发布时间】:2014-08-08 00:11:11
【问题描述】:

我正在使用 Picasso 从 URL 中提取 jpg,然后附加到 EditText。可以看出,我正在使用 Target 方法将图像从 URL 输入到我的 Drawable 中,然后将其附加到我的 EditText 中。但是,出现错误:

The method BitmapDrawable(Resources, Bitmap) is undefined for the type new Target(){}

地点:

BitmapDrawable(getBaseContext().getResources(), bitmap);

似乎出了什么问题?如何为我的操作正确配置此 Target 类实现?

追加到EditText的方法:

public void appendToMessageHistory(final String username,
            final String message) {
        if (username != null && message != null) {

            Picasso.with(getBaseContext()).load("http://localhost:3000/uploads/campaign/image/2/2.jpg").into(new Target() {

                @Override
                public void onPrepareLoad(Drawable arg0) {

                }

                @Override
                public void onBitmapLoaded(Bitmap bitmap, LoadedFrom arg1) {
                    Drawable drawImage = BitmapDrawable(
                            getBaseContext().getResources(), bitmap);
                    messageHistoryText.append(Html.fromHtml("<b>" + username
                            + ":" + "</b>" + "<br>"));
                    messageHistoryText.append(Html.fromHtml(message + "<hr>"
                            + "<br>")
                            + System.getProperty("line.separator") + "");

                    messageHistoryText.append(Html.fromHtml("<img src = '"
                            + drawImage + "'/>", imageGetter, null));
                }

                @Override
                public void onBitmapFailed(Drawable arg0) {

                }
            });

        }
    }

【问题讨论】:

    标签: android undefined picasso


    【解决方案1】:

    我怀疑你在BitmapDrawable 之前忘记了new 关键字。

    Drawable drawImage = BitmapDrawable(
                            getBaseContext().getResources(), bitmap);
    

    应该是

    Drawable drawImage = new BitmapDrawable(
                            getBaseContext().getResources(), bitmap);
    

    【讨论】:

    • 好吧,这让错误消失了,但它杀死了他的方法,它不会起作用。我会提出另一个问题
    猜你喜欢
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    相关资源
    最近更新 更多