Search This Blog

Tuesday, 19 June 2012

Issue when retrieving image from Server or network in Blackberry App

Hello Friends,
                       This thing made me frustrated for many days and then i found something very stupid thing hehehehe......had you ever face such a probllem that you know tht the image you want to use is on server but your app is unable to fetch tht image , this happens many a times ,like you are fetching multiple images but you found that some of them returned null......the problem is that  server admin named tht image with a space for ex : "red rose.jpg",here a space is there in image name , and whenever we want to fetch image we should switch this space with "%20" , you can easily do when you have only one image,but what will you do when the images are dynamic , you dont know the exact number of images and you dont know how many of them contains space in their names??? Here it is a function which will automatically replace the space with "%20".so you just need to use a for loop , and pass every single url of image to this function and it will replace the space with "%20" if found.....problem solved...

CODE:

public static String escapeHTML(String s){
    StringBuffer sb = new StringBuffer();
    int n = s.length();
       for (int i = 0; i < n; i++) {
          char c = s.charAt(i);
          switch (c) {
             case ' ': sb.append("%20"); break;
             default:  sb.append(c); break;
        }
    }
    return sb.toString();
}


How to use this function :

Suppose you have a url in string variable _image;

_image = "http:\\111.111.111.111\images\red rose.jpg";

Do this .....

String _str=escapeHTML(_image);

No comments:

Post a Comment