0
我想使用谷歌静态地图API,并下载我的位置的位图图像,并显示在我的应用程序作为图像,我写了这段代码,但我的应用程序停止,是什么问题?如何在Android中显示来自Uri的位图图像?
代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
String URL = "http://maps.google.com/maps/api/staticmap?center=48.858235,2.294571&zoom=15&size=200x200&sensor=false";
Bitmap bmp = null;
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
InputStream in = null;
try {
in = httpclient.execute(request).getEntity().getContent();
bmp = BitmapFactory.decodeStream(in);
in.close();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ImageView vi=(ImageView)findViewById(R.id.salak);
vi.setImageBitmap(bmp);
}
我刚写的这部分代码在OnCreate()函数,并在.xml文件一个图像浏览器来显示图像,但我的程序没有Corectly工作,怎么能我解决了这个问题?
你应该发布你的错误日志,在我看来,你可能会从主线程异常的网络崩溃,你应该看看异步任务做后台线程的网络 – JRowan 2014-09-27 19:39:54