您好,我必须获取 JSON 提要,这就是我使用此代码的原因:
try {
DefaultHttpClient httpclient = new DefaultHttpClient(
new BasicHttpParams());
HttpGet httpget = new HttpGet(CommonUtils.URL);
httpget.setHeader("Authorization", "Bearer " + CommonUtils.BEARER_TOKEN);
httpget.setHeader("Content-type", "application/json");
InputStream inputStream = null;
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(inputStream, "iso-8859-1"), 8);
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
inputStream.close();
} catch (Exception e) {
Log.e("GetFeedTask", "Error:" + e.getMessage());
}
当我在内部使用此代码AsyncTask
并调用它时,这是有效的,但当我直接调用它时onCreate()
不起作用并抛出异常。有什么问题?GetFeedTask
onCreate()
日志猫:
GetFeedTask Error: null