Android从服务端下载图片问题
============问题描述============
下图是我的Myeclipse项目的webroot文件夹,
![](http://images0.cnblogs.com/blog/554626/201410/182227363416769.png)
我想下载这个文件夹中的图片,可是我发现出现了诡异的错误。除了test01_upload_1.jpg以外,其它的图片都显示FileNotFoundException。
下面是我的测试代码和错误信息。
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============
你没发现你的其他图片的权限和1.jpg 的权限不一样吗?你查一下怎么改对,然后应该就 Ok 了
ps:无论哪个平台开发 android 都一样了,开发工具都是一致的,没什么差异的