У меня есть эта функция с тем, как я загружаю изображения в свое приложение, но я не знаю, почему я получил эту сеть по исключению основной нити. Вот это мой класс с функцией:Ошибка изображения android.os.NetworkOnMainThreadException
общественного класса Tail {
String story, description, title, location;
int imageID;
URL url;
public URL getUrl() {
return url;
}
public void setUrl(URL url) {
this.url = url;
}
public Tail(int imageID, String location, String description, String title, String story) {
this.imageID = imageID;
this.location = location;
this.title = title;
this.description = description;
this.story = story;
}
public Tail(String url, String location, String description, String title, String story) {
try {
this.url = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
this.location = location;
this.title = title;
this.description = description;
this.story = story;
}
public String getStory() {
return story;
}
public void setStory(String story) {
this.story = story;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public int getImageID() {
return imageID;
}
public void setImageID(int imageID) {
this.imageID = imageID;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public static Bitmap getImageBitmapFromUrl(URL url) {
Bitmap bm = null;
try {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn.getResponseCode() != 200) {
return bm;
}
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
try {
bm = BitmapFactory.decodeStream(bis);
} catch (OutOfMemoryError ex) {
bm = null;
}
bis.close();
is.close();
} catch (Exception e) {
}
return bm;
}
Знать кого, как можно решить эту проблему?
Если мой ответ помог вам, то plz проголосовать за него. Thanx –