I am parsing data using json object,and the data is also parsing from server,it shows in console but it got crash in emulator..
Here is my code:
public class jsonUtil {
static HttpURLConnection urlConnection;
public static HttpURLConnection openConnection() throws Exception {
int responseCode = -1;
try {
URL url = new URL("url display");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("POST");
urlConnection.setRequestProperty("Content-Type",
"application/x-www-form-encoded");
urlConnection.setRequestProperty(
"Content-Length",
"" + Integer.toString("category=breaking_news&latitude=&longitude="
.getBytes().length));
urlConnection.setRequestProperty("Content-Language", "en-US");
urlConnection.setRequestProperty("Accept-Encoding", "identity");
urlConnection.setUseCaches(false);
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setReadTimeout(10 * 1000);
urlConnection.setConnectTimeout(10 * 1000);
DataOutputStream wr = new DataOutputStream(
urlConnection.getOutputStream());
wr.writeBytes("category=breaking_news&latitude=&longitude=");
wr.flush();
wr.close();
responseCode = urlConnection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new Exception("Server not responding");
}
} catch (SocketException e) {
throw new Exception("Connection Time Out");
} catch (java.net.UnknownHostException unknownHostException) {
// TODO: handle exception
throw new Exception("unknownHostException");
} catch (Exception e) {
// TODO: handle exception
throw new Exception("Error Occured");
}
return urlConnection;
}
public static ArrayList<String> jsonParseList = new ArrayList<String>();
public static ArrayList<String> jsonParsing() {
StringBuffer buffer = new StringBuffer();
JSONArray array;
try {
try {
urlConnection = openConnection();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(urlConnection.getInputStream()));
String line = bufferedReader.readLine();
while (line != null) {
buffer.append(line);
line = bufferedReader.readLine();
}
bufferedReader.close();
if (buffer.toString() != null) {
try {
array = new JSONArray(buffer.toString());
JSONObject jsonObject;
for (int i = 0; i < array.length(); i++) {
jsonObject = array.getJSONObject(i);
String conv_title = jsonObject.getString("conv_title");
String content = jsonObject.getJSONObject("first_post")
.getString("content");
String creator = jsonObject.getJSONObject("first_post")
.getJSONObject("creator").getString("name");
Log.e("List Values", conv_title);
jsonParseList.add(conv_title);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonParseList;
}
}
Logcat:
' 06:35:21.637: E/List Activity(795): [] 05-30 06:35:21.687: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0 05-30 06:35:21.697: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0 05-30 06:35:21.717: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0 05-30 06:35:21.927: I/Choreographer(795): Skipped 144 frames! (795): Unexpected value from nativeGetEnabledTags: 0 05-30 06:35:22.158: I/Choreographer(795): Skipped 48 frames! The application may be doing too much work on its main thread. 05-30 06:35:22.317: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0 05-30 06:35:22.317: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0 05-30 06:35:22.337: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0 05-30 06:35:23.485: D/dalvikvm(795): GC_CONCURRENT freed 276K, 12% free 2894K/3288K, paused 69ms+3ms, total 134ms 05-30 06:35:23.642: E/List Values(795): Prime Minister Manmohan Singh to present UPA II report card today : E/List Values(795): US, India pledge to collaborate on combating terrorism 05-30 06:35:23.652: E/List Values(795): US, India pledge to collaborate on combating terrorism 05-30 06:35:23.652: E/List Values(795): Pakistan's real motives exposed 05-30 06:35:23.652: E/List Values(795): Pakistan's real motives exposed 05-30 06:35:23.657: E/List Values(795): Rupee recovers marginally, up 6 paise in early trade 05-30 06:35:23.657: E/List Values(795): Rupee recovers marginally, up 6 paise in early trade 05-30 06:35:23.657: E/List Values(795): 43 IPS officers in UP transferred 40 times in their career 05-30 06:35:23.657: E/List Values(795): 43 IPS officers in UP transferred 40 times in their career 05-30 06:35:23.657: E/List Values(795): Allahabad HC rejects Talwars' plea to examine 14 witnesses 05-30 06:35:23.657:E/List Values(795): Defence Secretary Shashi Kant Sharma to take over as new CAG 05-30 CAG 05-30 06:35:23.691: E/List Values(795): Power of Oklahoma tornado dwarfs Hiroshima bomb 05-30 06:35:23.691: E/List Values(795): Bank fined Rs 50,000 for not repaying fixed deposit 05-30 06:35:58.607: W/Trace(795): Unexpected value from nativeGetEnabledTags: 0