I'm struggling big time with a stupid problem which i can't seem to fix. Basicly what i do in my application is the following:
I download all the RSS content to a local database, including the enclosure of every feed (images) but not every feed contains an image.
about 10 of the 100 feeds don't contain an image What happens with the feeds that don't contain an image is shown in the following image:
http://i.stack.imgur.com/FTUBl.png
The feeds with no image get the image of the previouse feed for some reason...
I'll place all my code below in hope someone can tell me what in the world i'm doing wrong...
This part is where i download the image to the local storage, this function works correctly however for some reason the feed with no enclosure gets the enclosure of the previouse feed send back to it...
for (Message msg : wildLife){
String imageURL = msg.getEnclosure();
String imageName = imageURL.substring(imageURL.lastIndexOf("/"));
String imagePath = ImageDir + imageName;
//-- Call upon the function that will download the image.
if (imageURL !=null){
DownloadFromUrl(imageURL, imagePath);
}
//-- We add all rows we find in the rrs feed to our local stored database.
db.addWildlifeRow(
msg.getTitle(),
msg.getDescription(),
开发者_运维知识库 "Empty slot",
imagePath,
msg.getLink());
}
I checked in the RSS parser and it doesn't store the same URL twice. So no problem there. It goes wrong (for as far as i know) when requisting the URL enclosure from a message item.
Is there anyone who might have encountered this same problem?
All advice is welcome i've been stuck in this problem for days now, and i can't seem to figure it out...
If you would require more code to find a possible solution just ask and i will provide it.
P.S. it goes wrong before placing the data into my database, so when reading the info from the message out and placing it in the database, its already gone wrong there. The enclosure is copied from the reviouse one (if there was none)
Regards, joery
//-- Call upon the function that will download the image.
if (imageURL !=null){
DownloadFromUrl(imageURL, imagePath);
}
else
imageview.setImageDrawable(null);
Try adding an else part here and clear any old image in ur imageview
Have you tried walking through it in debug?
I agree that it seems as though
String imageURL = msg.getEnclosure();
must be always returning something - as if msg.getEnclosure() returned null for items with out an image then you would get NullPointerException on the following line at
String imageName = imageURL.substring(imageURL.lastIndexOf("/"));
If you could provide the RSS parsing code that could be useful - I assume other than that there is no other pre-processing of the Wildlife message set?
精彩评论