omid_student
دوشنبه 23 دی 1392, 11:20 صبح
سلام دوستان
من کد زیر از اینترنت گرفتم وقتی اجراش میکنم خطای زیر میده
چطور میشه حلش کرد؟
public Bitmap LoadImageFromUrl(String URL)
{
String imageurl = URL;
InputStream in = null;
try {
Log.i("URL", imageurl);
URL url = new URL(imageurl);
URLConnection urlConn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) urlConn;
httpConn.connect();
in = httpConn.getInputStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bmpimg = BitmapFactory.decodeStream(in);
return bmpimg;
}
خطا هم اینه
android.os.NetworkOnMainThreadException
من کد زیر از اینترنت گرفتم وقتی اجراش میکنم خطای زیر میده
چطور میشه حلش کرد؟
public Bitmap LoadImageFromUrl(String URL)
{
String imageurl = URL;
InputStream in = null;
try {
Log.i("URL", imageurl);
URL url = new URL(imageurl);
URLConnection urlConn = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) urlConn;
httpConn.connect();
in = httpConn.getInputStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bmpimg = BitmapFactory.decodeStream(in);
return bmpimg;
}
خطا هم اینه
android.os.NetworkOnMainThreadException