在我的應用程序中,我必須從url下載圖像。但網址包含it.So我編碼爲UTF-8格式,並嘗試下載一些阿拉伯charsters,但它顯示空指針的警告,因此圖像沒有下載:在阿拉伯字符文件名(阿拉伯字符)下載圖像
我的代碼:
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());
我的URL是這樣的:
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)
請幫我解決這個..Thanks提前..
我也不能訪問該網址,網站你在你的問題中似乎不是一個有效的問題。 –
請從'DownloadString.java:209'中添加一些代碼# – thepoosh
謝謝Mahmoud Hossam ..我修改了網址..我無法給有效的網址..我在我的瀏覽器中檢查了它.. – Subburaj