Downloading an Image
I am downloading an image and then setting this in a custom view in my app. I am getting very different results depending on 开发者_如何学JAVAhow I run the app. The problem is when I download the image
public Drawable getImage() throws IOException, MalformedURLException {
InputStream is = (InputStream) new java.net.URL(url).getContent();
Drawable test = Drawable.createFromStream(is, "name");
return test;
}//getImage
Sometimes test shows as null, sometimes it's downloaded. I want to find out why it is doing this. The problem I have is that the only time this occurs is when I run the app in normal mode (opposed to debug) on a HTC dream. If I run is in debug on the phone is normally returns the image. If I run it on the emulator (in debug or not) is normally returns the image. So the problem is occurring when I can't access the information I need via debug.
Is there any code that I can add to monitor the download of the image?
You can add log messages to logcat that can be seen outside of debug mode as long as the device is connected to the computer. To log, use the verbose, debug, information, warning, or error log levels shown below (respectively)
Log.v(...)
Log.d(...)
Log.i(...)
Log.w(...)
Log.e(...)
This will help you narrow down the parameters used, results returned, and any other information you need to figure out where this error is occuring.
精彩评论