============ Problem Description ============
Why do you write this? Unable to get picture resources on the server
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Myimg= (ImageView) Findviewbyid (r.id.imagetest);
try {
URL url=new url (url1);
InputStream Is=url.openstream ();
Bitmap=bitmapfactory.decodestream (IS);
Myimg.setimagebitmap (bitmap);
Is.close ();
} catch (Exception e) {
Todo:handle exception
E.printstacktrace ();
}
}
}
You can write it in a different way.
protected void OnCreate (Bundle savedinstancestate) {
New Thread ()
{
public void Run ()
{
try {
URL url = new URL (URL1);
InputStream Is=url.openstream ();
Bitmap=bitmapfactory.decodestream (IS);
Is.close ();
} catch (Exception e) {
TODO Auto-generated catch block
E.printstacktrace ();
}
Myhandler.sendemptymessage (0);
};
}.start ();
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
Myimg= (ImageView) Findviewbyid (R.ID.IMAGETEST1);
Myhandler=new Handler ()
{
public void Handlemessage (Message msg)
{
if (msg.what==0)
{
Myimg.setimagebitmap (bitmap);
}
};
};
}
}
Ask the great God for advice, the first reason why the picture is not displayed
============ Solution 1============
Because you performed network operations in the main thread of the UI.
About URLs getting picture resources from the server