Reputation: 10777
I am trying to fetch an image from a link, here is what i do:
public class FetchImage extends AsyncTask<String, Void, Drawable> {
public static Drawable LoadImageFromWeb(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
} catch (IOException e) {
Log.e("HATA", "THERE is an error", e);
return null;
}
}
@Override
protected Drawable doInBackground(String... params) {
String url = params[0];
return LoadImageFromWeb(url);
}
@Override
protected void onPostExecute(Drawable drawable) {
}
}
For the url http://www.marketimyilmazlar.com/image/cache/data/INDIRIM/ao/Pril_TR_MAX_750ml_Lemon_189227_print_1772H_1772W-500x500.png i succesfully get the image. However, when i try the url http://www.marketimyilmazlar.com/image/cache/data/cay/Ncapkırmızı-500x500.jpg it gives me a filenotfoundexception. Here is the stactrace:
02-11 18:22:15.475: E/HATA(16015): THERE is an error
02-11 18:22:15.475: E/HATA(16015): java.io.FileNotFoundException: http://www.marketimyilmazlar.com/image/cache/data/cay/Ncapkırmızı-500x500.jpg
02-11 18:22:15.475: E/HATA(16015): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186)
02-11 18:22:15.475: E/HATA(16015): at java.net.URLConnection$DefaultContentHandler.getContent(URLConnection.java:1018)
02-11 18:22:15.475: E/HATA(16015): at java.net.URLConnection.getContent(URLConnection.java:199)
02-11 18:22:15.475: E/HATA(16015): at java.net.URL.getContent(URL.java:447)
02-11 18:22:15.475: E/HATA(16015): at com.example.barcodescanner.FetchImage.LoadImageFromWeb(FetchImage.java:18)
02-11 18:22:15.475: E/HATA(16015): at com.example.barcodescanner.FetchImage.doInBackground(FetchImage.java:30)
02-11 18:22:15.475: E/HATA(16015): at com.example.barcodescanner.FetchImage.doInBackground(FetchImage.java:1)
02-11 18:22:15.475: E/HATA(16015): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-11 18:22:15.475: E/HATA(16015): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-11 18:22:15.475: E/HATA(16015): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-11 18:22:15.475: E/HATA(16015): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-11 18:22:15.475: E/HATA(16015): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-11 18:22:15.475: E/HATA(16015): at java.lang.Thread.run(Thread.java:841)
It is really weird. Can it be because of some Turkish characters in the link such as "ı", not "i" ? If that is so, how can i fix it?
Thanks
EDIT: I just realized another thing, when i open the followink link in the browser,
http://www.marketimyilmazlar.com/image/cache/data/DUZELTME/dvm/screenshot 7-500x500.jpg
I see that the link changes and becomes :
http://www.marketimyilmazlar.com/image/cache/data/DUZELTME/dvm/screenshot%207-500x500.jpg
So, why is that happening and why cannot i use the first link while trying to fetch the image?
Upvotes: 0
Views: 645
Reputation: 1197
You are right about the "ı" Turkish character: if you look your answer, you will see that Stackoverflow does not recognize automatically the url that is giving you problems.
With Firefox i can access to your url, but when i check the url with the developers tools, the url is http://www.marketimyilmazlar.com/image/cache/data/cay/Ncapk%C4%B1rm%C4%B1z%C4%B1-500x500.jpg Take note that the non ASCII characters are escaped.
Edit 1:
For access to an url with nons ascii characters, you need to encode the part of the url with the special characters before make the request: URL encoding in Android
Upvotes: 2
Reputation: 4243
I think you can find the answer here:
Invalid URI with Chinese characters (Java)
Upvotes: 1