0

In my application i have to download an image from url. But my url contains some arabic charsters in it.So i encoded to UTF-8 format and trying to download it,but it shows nullpointer warning,so image is not downloading:

my code:

String urlDecode=URLDecoder.decode(urlpath,"UTF-8");
            Log.i("urlDecode", urlDecode);
            url = new URL(urlDecode);..

//          url = new URL(URLDecoder.decode(urlpath,"UTF-8"));
            System.out.println("url="+url);
            Bitmap bmp ;
//          try
//          {
            String filename = urlpath.substring(urlpath.lastIndexOf("/") + 1,
                    urlpath.length());
            bmp = BitmapFactory.decodeStream(url.openConnection()
                    .getInputStream());

My URL is like this:

http://vvvv.com/book_images/398_مقاصد _2الشريعة.jpg

My logcat:

06-27 11:46:19.868: W/System.err(18859): java.lang.NullPointerException
06-27 11:46:19.868: W/System.err(18859):    at DownloadString.DownloadImageFromURL(DownloadString.java:209)
06-27 11:46:19.868: W/System.err(18859):    at DownloadString.DownloadStringMethod(DownloadString.java:114)
06-27 11:46:19.868: W/System.err(18859):    at ThumbnailView$GetTask.doInBackground(ThumbnailView.java:797)
06-27 11:46:19.868: W/System.err(18859):    at ThumbnailView$GetTask.doInBackground(ThumbnailView.java:1)
06-27 11:46:19.868: W/System.err(18859):    at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-27 11:46:19.868: W/System.err(18859):    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-27 11:46:19.868: W/System.err(18859):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-27 11:46:19.868: W/System.err(18859):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-27 11:46:19.868: W/System.err(18859):    at java.lang.Thread.run(Thread.java:856)

Please help me to solve this..Thanks in advance..

Subburaj
  • 5,114
  • 10
  • 44
  • 87

1 Answers1

0

Use the following web encoding tool and encode the Arabic URL and then hardcode to the url in the program and try
http://meyerweb.com/eric/tools/dencoder/

blganesh101
  • 3,647
  • 1
  • 24
  • 44
  • Thanks blganesh101.. i will try and say. – Subburaj Jun 27 '13 at 11:38
  • I pasted my url and encode it and pasted that in my browser ,but the image is not there.. – Subburaj Jun 27 '13 at 11:42
  • You need to paste it in the URL and use it. btw to help you on this, i found another link where others are facing the same problem, may be you can have a look. http://stackoverflow.com/questions/6519746/url-decode-in-java-6#6603584 – blganesh101 Jun 27 '13 at 11:55
  • My problem is that my url contains arabic letters,also i used "UTF-8" encoding as in my code in my above post..So what can i do now..The image size is 0.00kb.. – Subburaj Jun 27 '13 at 12:01