简体   繁体   中英

java.net.UnknownHostException: Unable to resolve host “s3-ap-northeast-1.amazonaws.com”: No address associated with hostname

I use the code below to get image:

public Bitmap loadImageFromUrl(String urlStr) {
    try {
        BufferedInputStream bis = new BufferedInputStream(new URL(urlStr).openStream());
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(baos);
        copy(bis, bos);
        bos.flush();
        bos.close();
        bis.close();
        return BitmapFactory.decodeByteArray(baos.toByteArray(), 0, baos.size());

    } catch (Exception e) {
        e.printStackTrace();
    }

I'm sure of the permisson and wifi connection. such as:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

If you are getting this error then might be there is 2 issue.

1) Either you forget to add permission of internet in android manifest.

 <uses-permission android:name="android.permission.INTERNET" />

2) If you are running in real device then your device is not connected with internet. Check whether your device is connected with internet or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM