Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieving bitmap image from a URL ,getting nullpointerexception randomly in android

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing a project with google maps in it.I am trying to retrieve bitmap images from a URL and it works fine ,but not all the time

The code i am using to retrieve the url is inside a async class.

The async class:


I am calling the async class as:



The problem is that the variable pinbit gets NPE randomly.Many times the desired result is seen.But sometimes out of random i get NPE.So i think there is something wrong with the doInBackground method where the web operation takes place.How do i ensure that the code with the web operation doesnt break?

The LOGCAT:

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect it is the "Bimap" reference assigned in line 19 rather than the one assigned in line 33 that is null, correct? The javadocs of the former say that it can be null, whereas the javadocs of the latter don't mention that.

It says: "If the input stream is null, or cannot be used to decode a bitmap, the function returns null." - not particularly helpful, unfortunately.
 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So can you suggest a fix?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, except to try different inputs and see if you can find a pattern when it occurs, and if so, work around that. I assume you have already googled the problem.
 
this is supposed to be a surprise, but it smells like a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic