【发布时间】:2014-03-27 14:15:37
【问题描述】:
我试图从互联网上检索图像并找到类似的示例,然后稍微更改了我找到的代码。但是当我运行我的代码时,我得到了这个异常android.os.NetworkOnMainThreadException。然后我搜索了解决方案并注意到我应该使用@ 987654322@ 这样做的类。问题很简单,我只是无法在每一行代码中都出现语法错误。请您帮助如何修复此代码并使其正常运行。提前致谢
class BackroundActivity extends AsyncTask<Void, Bitmap, Void>
{
@Override
protected Bitmap doInBackground(String src) throws IOException {
HttpURLConnection con = null;
URL url=new URL(src);
con=(HttpURLConnection) url.openConnection();
con.setDoInput(true);
InputStream input=con.getInputStream();
Bitmap bmp=BitmapFactory.decodeStream(input);
return bmp;
}
【问题讨论】: