标签:android blog http io os ar java for sp
============问题描述============
package com.example.imagedownload; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView imageView; private String imageUrl = "http://10.0.2.2:8080/BBStuServlet/573da5540dee470f9ec41de207e83b73.jpg"; final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { System.out.println(msg.obj); imageView.setImageDrawable((Drawable) msg.obj); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.imageView1); new Thread(new Runnable() { @Override public void run() { try { Drawable drawable = Drawable.createFromStream(new URL( imageUrl).openStream(), "image.jpg"); System.out.println("draw = " + drawable); Message msg = new Message(); msg.obj = drawable; handler.sendMessage(msg); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); } }
09-28 12:29:28.243: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property 09-28 12:29:28.334: E/Trace(3029): error opening trace file: No such file or directory (2) 09-28 12:29:28.684: W/System.err(3029): java.io.FileNotFoundException: http://10.0.2.2:8080/BBStuServlet/573da5540dee470f9ec41de207e83b73.jpg 09-28 12:29:28.724: W/System.err(3029): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:186) 09-28 12:29:28.724: W/System.err(3029): at java.net.URL.openStream(URL.java:462) 09-28 12:29:28.724: W/System.err(3029): at com.example.imagedownload.MainActivity$2.run(MainActivity.java:40) 09-28 12:29:28.735: W/System.err(3029): at java.lang.Thread.run(Thread.java:856) 09-28 12:29:28.774: E/SurfaceFlinger(37): ro.sf.lcd_density must be defined as a build property
============解决方案1============
标签:android blog http io os ar java for sp
原文地址:http://www.cnblogs.com/lianxu61/p/4033873.html