Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:41:39+00:00 2026-06-05T08:41:39+00:00

I am trying to get image from URL to ImageView I’m curently using this

  • 0

I am trying to get image from URL to ImageView I’m curently using this class. I have added permission to connect to internet write_SD card and so on, to AndroidManifest the problem is that it returns error java.lang.NullPointerException when I try to add image to ImageView using this function:`

public void download(String url, ImageView imageView) {
    try
    {    
        if (cancelPotentialDownload(url, imageView)) 
        {
             //TODO:Caching code right here
             String filename = String.valueOf(url.hashCode());
             File f = new File(getCacheDirectory(hm), filename);

              // Is the bitmap in our cache?
              Bitmap bitmap = BitmapFactory.decodeFile(f.getPath());

              //No? download it
              if(bitmap == null){
                  BitmapDownloaderTask task = new BitmapDownloaderTask(imageView);
                  DownloadedDrawable downloadedDrawable = new DownloadedDrawable(task);
                  imageView.setImageDrawable(downloadedDrawable);
                  task.execute(url);
              }else{
                  //Yes? set the image
                  imageView.setImageBitmap(bitmap);
              }
         }
    }catch (Exception e) {
        // TODO: handle exception
        Log.e("",e.toString());
    }
}`

The question is what could be wrong and how could i fix this?
i will be pleased if you could point me in the right direction.

Logcat:

`06-06 09:38:19.686: E/AndroidRuntime(18832): java.lang.NullPointerException
06-06 09:38:19.686: E/AndroidRuntime(18832):    at com.jandans.geos.ImageDownloader.download(ImageDownloader.java:51)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at com.jandans.geos.vaikpied$1.onItemClick(vaikpied.java:98)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at android.widget.AdapterView.performItemClick(AdapterView.java:284)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at android.widget.ListView.performItemClick(ListView.java:3513)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:1849)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at android.os.Handler.handleCallback(Handler.java:587)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at android.os.Handler.dispatchMessage(Handler.java:92)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at android.os.Looper.loop(Looper.java:130)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at android.app.ActivityThread.main(ActivityThread.java:3835)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at java.lang.reflect.Method.invokeNative(Native Method)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at java.lang.reflect.Method.invoke(Method.java:507)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
06-06 09:38:19.686: E/AndroidRuntime(18832):    at dalvik.system.NativeStart.main(Native Method)

`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:41:41+00:00Added an answer on June 5, 2026 at 8:41 am

    Try below one –

    public class ImgLoadFrmWebActivity extends Activity {
    
        ImageView imv1;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Drawable image = ImageOperations(getApplicationContext(),"http://hvz.eu5.org/upload/1.jpg","image");
            ImageView imgView = (ImageView)findViewById(R.id.imageView1);
            imgView = (ImageView)findViewById(R.id.imageView1);
            imgView.setImageDrawable(image);
        }
        private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
            try {
                InputStream is = (InputStream) this.fetch(url);
                Drawable d = Drawable.createFromStream(is, "src");
                return d;
            } catch (MalformedURLException e) {
                e.printStackTrace();
                return null;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        public Object fetch(String address) throws MalformedURLException,IOException {
            URL url = new URL(address);
            Object content = url.getContent();
            return content;
        }
    }
    

    Make sure the permission is added in your manifest file –

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    

    Simply customize this layout with your needs. Hope this helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get an image from an url using a byte stream. But
I am trying to get an image from an HTTP server using Perl. I
I am using this code to display image from URL, but it is not
I'm trying to get a image from particular URL but it throws FileNotFoundException .
I'm trying to get an image from an URL but when I save it
I'm trying to get an image from an URL and it doesn't seem to
I'm trying to get an image's Dimension online from a URL, like the person
Im trying to get HTML image tag url from the given string. There should
I'm trying to get an image from URL and save it to the isolated
I'm trying to get an image off the internet from an URL in java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.