安卓 异步加载报错
代码如下publicclassMainActivityextendsAppCompatActivity{privatestaticStringUrl="http://ww...
代码如下
public class MainActivity extends AppCompatActivity { private static String Url="http://www.imooc.com/api/teacher?type=4&num=30"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new NewsAsyncTack().execute(Url); } public class NewsAsyncTack extends AsyncTask<String,Void,List<NewsBean>>{ @Override protected List<NewsBean> doInBackground(String... params) { List<NewsBean> list = new ArrayList<>(); String result=""; try { URL url = new URL(params[0]); InputStream is =url.openStream(); InputStreamReader isr = new InputStreamReader(is,"UTF-8"); BufferedReader br = new BufferedReader(isr); String readString; while ((readString=br.readLine())!=null){ result+=readString; } Log.e("HXY",result); } catch (MalformedURLException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } return list; } }}
求大神 展开
public class MainActivity extends AppCompatActivity { private static String Url="http://www.imooc.com/api/teacher?type=4&num=30"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new NewsAsyncTack().execute(Url); } public class NewsAsyncTack extends AsyncTask<String,Void,List<NewsBean>>{ @Override protected List<NewsBean> doInBackground(String... params) { List<NewsBean> list = new ArrayList<>(); String result=""; try { URL url = new URL(params[0]); InputStream is =url.openStream(); InputStreamReader isr = new InputStreamReader(is,"UTF-8"); BufferedReader br = new BufferedReader(isr); String readString; while ((readString=br.readLine())!=null){ result+=readString; } Log.e("HXY",result); } catch (MalformedURLException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } return list; } }}
求大神 展开
1个回答
2015-12-06 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询