0

I'm trying to display <img> tags in json string and I using the accepted answer in this question but Android Studio is complaining "cannot resolve symbol urlDrawable

Please can anybody tell me why this is happening and how to fix it?

UILImageGetter

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.view.View;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;


public class UILImageGetter implements Html.ImageGetter{
    Context c;
    TextView conatiner;
    urlDrawable;

    public UILImageGetter(View textView, Context context) {
        this.c = context;
        this.conatiner = (TextView) textView;
    }

    @Override
    public Drawable getDrawable(String source) {
        urlDrawable = new UrlImageDownloader(c.getResources(), source);
        urlDrawable.drawable = c.getResources().getDrawable(R.drawable.default_thumb);

        ImageLoader.getInstance().loadImage(source, new SimpleListener(urlDrawable));
        return urlDrawable;
    }

    private class SimpleListener extends SimpleImageLoadingListener {
        UrlImageDownloader mUrlImageDownloader;

        public SimpleListener(UrlImageDownloader downloader) {
            super();
            mUrlImageDownloader= downloader;
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            int width = loadedImage.getWidth();
            int height = loadedImage.getHeight();

            int newWidth = width;
            int newHeight = height;

            if (width > conatiner.getWidth()) {
                newWidth = conatiner.getWidth();
                newHeight = (newWidth * height) / width;
            }

            if (view != null) {
                view.getLayoutParams().width = newWidth;
                view.getLayoutParams().height = newHeight;
            }

            Drawable result = new BitmapDrawable(c.getResources(), loadedImage);
            result.setBounds(0, 0, newWidth, newHeight);

            mUrlImageDownloader.setBounds(0, 0, newWidth, newHeight);
            mUrlImageDownloader.mDrawable = result;

            conatiner.setHeight((conatiner.getHeight() + result.getIntrinsicHeight()));
            conatiner.invalidate();
        }

    }

    private class UrlImageDownloader extends BitmapDrawable {
        public  Drawable mDrawable;

        public UrlImageDownloader(Resources resources, String filepath) {
            super(resources, filepath);
            mDrawable = new BitmapDrawable(resources, filepath);
        }

        @Override
        public void draw(Canvas canvas) {
            if (mDrawable != null) {
                mDrawable.draw(canvas);
            }
        }
    }
}
Community
  • 1
  • 1
Roseyk
  • 97
  • 9

2 Answers2

1

You haven't assigned a type to urlDrawable; This portion of code contains the error:

public class UILImageGetter implements Html.ImageGetter{
    Context c;
    TextView conatiner;
    urlDrawable;

Try this:

public class UILImageGetter implements Html.ImageGetter{
    Context c;
    TextView conatiner;
    UrlImageDownloader urlDrawable;
ajohnston777
  • 101
  • 3
  • 7
0

Java is a strongly typed language, which means that all variables must be declared as being of some type.

Since you don't specify a type for urlDrawable, the compiler doesn't understand that you're declaring a variable.

Simply replace

urlDrawable;

with

UrlImageDownloader urlDrawable;
Magnus
  • 17,157
  • 19
  • 104
  • 189
  • Should I do that for all instances of `urlDrawable` or just the first one? – Roseyk Apr 17 '16 at 16:36
  • You need to do it for every variable of type `URLImageDownloader` that you declare. I see that you're already doing it for `UrlImageDownloader mUrlImageDownloader;` for example. Of course you only have to do this when you [declare a variable](http://java.about.com/od/understandingdatatypes/a/declaringvars.htm), not when you use it! – Magnus Apr 17 '16 at 16:37