S
Snipestyle
Erfahrenes Mitglied
- 3
Hallo,
ich sitze nun seit einiger Zeit daran ein Image aus dem Internet also dessen URL in das ImageView zu laden.
So gehe ich vor:
und dann wird es so benutzt:
In der Logcat steht das:
Als Ergebnis bekomme ich einfach ein leeres ImageView angezeigt
Ich hoffe ihr könnt mir helfen, bin da gerade ein wenig überfragt
Der ursprüngliche Beitrag von 18:11 Uhr wurde um 18:27 Uhr ergänzt:
AAHHHH !!
Kann geschlossen und gelöscht werden
Habe meinen Fehler gefunden
ich sitze nun seit einiger Zeit daran ein Image aus dem Internet also dessen URL in das ImageView zu laden.
So gehe ich vor:
Code:
private Bitmap bitmap;
public Bitmap getBitmapFromURL(String src)
{
try
{
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (Exception e)
{
e.printStackTrace();
return null;
}
}
Code:
ImageView image = (ImageView) findViewById(R.id.imageView1);
bitmap = getBitmapFromURL("http://images.tagseoblog.de/bilder/bild-foto/bild.jpg");
image.setImageBitmap(bitmap);
Code:
01-13 17:00:39.957: W/System.err(870): android.os.NetworkOnMainThreadException
01-13 17:00:40.007: D/dalvikvm(870): GC_CONCURRENT freed 219K, 3% free 10134K/10439K, paused 6ms+11ms
01-13 17:00:40.007: W/System.err(870): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1084)
01-13 17:00:40.007: W/System.err(870): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
01-13 17:00:40.007: W/System.err(870): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
01-13 17:00:40.007: W/System.err(870): at java.net.InetAddress.getAllByName(InetAddress.java:220)
01-13 17:00:40.007: W/System.err(870): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
01-13 17:00:40.007: W/System.err(870): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
01-13 17:00:40.007: W/System.err(870): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
01-13 17:00:40.007: W/System.err(870): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
01-13 17:00:40.007: W/System.err(870): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
01-13 17:00:40.007: W/System.err(870): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
01-13 17:00:40.007: W/System.err(870): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
01-13 17:00:40.017: W/System.err(870): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
01-13 17:00:40.017: W/System.err(870): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
01-13 17:00:40.017: W/System.err(870): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
01-13 17:00:40.017: W/System.err(870): at de.petersen.cam_connect.MainActivity.getBitmapFromURL(MainActivity.java:70)
01-13 17:00:40.017: W/System.err(870): at de.petersen.cam_connect.MainActivity$2$1$1.run(MainActivity.java:336)
01-13 17:00:40.017: W/System.err(870): at android.os.Handler.handleCallback(Handler.java:605)
01-13 17:00:40.027: W/System.err(870): at android.os.Handler.dispatchMessage(Handler.java:92)
01-13 17:00:40.027: W/System.err(870): at android.os.Looper.loop(Looper.java:137)
01-13 17:00:40.027: W/System.err(870): at android.app.ActivityThread.main(ActivityThread.java:4340)
01-13 17:00:40.027: W/System.err(870): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 17:00:40.027: W/System.err(870): at java.lang.reflect.Method.invoke(Method.java:511)
01-13 17:00:40.047: W/System.err(870): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-13 17:00:40.057: W/System.err(870): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-13 17:00:40.057: W/System.err(870): at dalvik.system.NativeStart.main(Native Method)
Als Ergebnis bekomme ich einfach ein leeres ImageView angezeigt
Ich hoffe ihr könnt mir helfen, bin da gerade ein wenig überfragt
Der ursprüngliche Beitrag von 18:11 Uhr wurde um 18:27 Uhr ergänzt:
AAHHHH !!
Kann geschlossen und gelöscht werden
Habe meinen Fehler gefunden