在我的应用程序中,我必须从网址下载图像。但我的网址中包含一些阿拉伯语字符。所以我编码为UTF-8格式并尝试下载,但它显示空指针警告,因此图像不下载:
我的代码:
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());
我的网址是这样的:
http://vvvv.com/book_images/398_مقاصد _2الشريعة.jpg
我的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)
请帮我解决这个问题..提前谢谢..