我没有得到任何错误,但应用程序停止。 我想从YouTube标题中填入数组列表。我想从YouTube上解析Json数据,但程序已停止。 我该如何解决这个问题?哪里错了?youtube Json - C错误
feedUrl="https://gdata.youtube.com/feeds/api/users/muyap/uploads?v=2&alt=jsonc&max-results=2";
HttpClient client = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(feedUrl);
HttpResponse responce;
try {
responce = client.execute(getRequest);
StatusLine statusLine = responce.getStatusLine();
int statusCode = statusLine.getStatusCode();
if(statusCode!=200)
{
Toast.makeText(YouTube.this, "Yükleme Gerçekleşmedi", Toast.LENGTH_LONG).show();
}else{
InputStream JsonStream=responce.getEntity().getContent();
BufferedReader reader= new BufferedReader(new InputStreamReader(JsonStream));
StringBuilder builder = new StringBuilder();
String line;
while((line=reader.readLine())!=null)
{
builder.append(line);
}
String JSONdata = builder.toString();
Log.i("JsonData",JSONdata);
JSONObject json = new JSONObject(JSONdata);
JSONObject data = json.getJSONObject("data");
JSONArray items=data.getJSONArray("items");
for(int i=0;i<items.length();i++)
{
JSONObject video=items.getJSONObject(i);
videoArrayList.add(video.getString("title"));
}
list = (ListView)findViewById(R.id.listView1);
list.setAdapter(new ArrayAdapter<String>(YouTube.this, android.R.layout.simple_list_item_1,videoArrayList));
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我想显示日志1和2
您的'JSONdata'是否打印在'Log'中? – Hariharan
@Tamilan不,应用程序在活动运行时停止 –
您没有错误。没有在日志中打印。如果还没有收到,再次运行应用程序。尝试清理该项目并运行。 – Hariharan