Unknown Reason for Runtime Error - google-maps

I was starting out with google map Api's. Following some examples on the internet.I came up with these code. I was able to get the Json code quite easily by crating HttpURLCOnnection but somehow I am getting a runtime error.Somehow i am unable to create a Json Object.I searched quite a bit,but didn't find any relation between JSONObject and Runtimeerror
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
public class Parser {
public static void main(String args[])
{
String response="";
int lat1=20270000,lon1=85520000,lat2=20264500,lon2=85835500;
String urlString="https://maps.googleapis.com/maps/api/directions/json?origin="+Double.toString((double)lat1/1E6)+","+Double.toString((double) lon1/1E6)+"&destination="+Double.toString((double)lat2/1E6)+","+Double.toString((double) lon2/1E6)+"&sensor=true";
HttpURLConnection urlConnection= null;
URL url = null;
try{
url = new URL(urlString.toString());
urlConnection=(HttpURLConnection)url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.connect();
InputStream inStream = urlConnection.getInputStream();
BufferedReader bReader = new BufferedReader(new InputStreamReader(inStream));
String temp;
while((temp = bReader.readLine()) != null){
response += temp;
}
System.out.println(response);
bReader.close();
inStream.close();
urlConnection.disconnect();
}
catch(Exception e){}
ArrayList<Bundle> list = new ArrayList<Bundle>();
try {
System.out.println(response.toString()); // uptil here every thing is fine..... I am getting correct Json text.
JSONObject jsonObject = new JSONObject(response); //I am getting a runtime error in this line. Can't figure out the reason
System.out.println(jsonObject);
JSONArray routesArray= jsonObject.getJSONArray("routes");
JSONObject route = routesArray.getJSONObject(0);
JSONArray legs = route.getJSONArray("legs");
JSONObject leg = legs.getJSONObject(0);
JSONObject durationObject = leg.getJSONObject("duration");
String duration = durationObject.getString("text");
System.out.println("egferg"+duration);
}
catch(Exception e1){e1.printStackTrace();}
}
}

Related

java.lang.NoSuchMethodError: org.codehaus.jackson.JsonFactory.enable(Lorg/codehaus/jackson/JsonParser$Feature;

I am getting below error while executing java code in Eclipse (I am not using Maven)
Exception in thread "main" java.lang.NoSuchMethodError: org.codehaus.jackson.JsonFactory.enable(Lorg/codehaus/jackson/JsonParser$Feature;)Lorg/codehaus/jackson/JsonFactory;
at org.apache.avro.Schema.<clinit>(Schema.java:88)
at org.apache.avro.Schema$Parser.parse(Schema.java:997)
at com.rishav.avro.AvroExampleWithoutCodeGeneration.serialize(AvroExampleWithoutCodeGeneration.java:36)
at com.rishav.avro.AvroExampleWithoutCodeGeneration.main(AvroExampleWithoutCodeGeneration.java:94)
I am using jars:
avro-1.8.2.jar
java-jason.jar
jason-simple-1.1.1.jar
org.apache.sling.commons.json-2.0.6-sources.jar
org.apache.sling.launchpad-9
jackson-core-asl-1.1.0.jar
jackson-mapper-asl-1.1.0.jar
Line 36 --> Schema schema = new Schema.Parser().parse(new File("StudentActivity.avsc"));
package com.rishav.avro;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.LinkedHashMap;
import org.apache.avro.Schema;
import org.apache.avro.file.DataFileReader;
import org.apache.avro.file.DataFileWriter;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
//import org.apache.avro.io.BinaryDecoder;
import org.apache.avro.io.DatumReader;
import org.apache.avro.io.DatumWriter;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONObject;
public class AvroExampleWithoutCodeGeneration {
public void serialize() throws JsonParseException, JsonProcessingException, IOException {
InputStream in = new FileInputStream("StudentActivity.json");
// create a schema
Schema schema = new Schema.Parser().parse(new File("StudentActivity.avsc"));**// THIS IS LINE 36**
// create a record to hold json
GenericRecord AvroRec = new GenericData.Record(schema);
// create a record to hold course_details
GenericRecord CourseRec = new GenericData.Record(schema.getField("course_details").schema());
// this file will have AVro output data
File AvroFile = new File("resources/StudentActivity.avro");
// Create a writer to serialize the record
DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(schema);
DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<GenericRecord>(datumWriter);
dataFileWriter.create(schema, AvroFile);
// iterate over JSONs present in input file and write to Avro output file
ObjectMapper mapper = new ObjectMapper();
Iterator it= (Iterator) mapper.readValue(new JsonFactory().createJsonParser(in), JSONObject.class);
while (it.hasNext())
{
//for (Iterator it = mapper.readValues(new JsonFactory().createJsonParser(in), JSONObject.class); it.hasNext();) {
JSONObject JsonRec = (JSONObject) it.next();
AvroRec.put("id", JsonRec.get("id"));
AvroRec.put("student_id", JsonRec.get("student_id"));
AvroRec.put("university_id", JsonRec.get("university_id"));
LinkedHashMap CourseDetails = (LinkedHashMap) JsonRec.get("course_details");
CourseRec.put("course_id", CourseDetails.get("course_id"));
CourseRec.put("enroll_date", CourseDetails.get("enroll_date"));
CourseRec.put("verb", CourseDetails.get("verb"));
CourseRec.put("result_score", CourseDetails.get("result_score"));
AvroRec.put("course_details", CourseRec);
dataFileWriter.append(AvroRec);
} // end of for loop
in.close();
dataFileWriter.close();
} // end of serialize method
public void deserialize () throws IOException {
// create a schema
Schema schema = new Schema.Parser().parse(new File("resources/StudentActivity.avsc"));
// create a record using schema
GenericRecord AvroRec = new GenericData.Record(schema);
File AvroFile = new File("resources/StudentActivity.avro");
DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(schema);
DataFileReader<GenericRecord> dataFileReader = new DataFileReader<GenericRecord>(AvroFile, datumReader);
System.out.println("Deserialized data is :");
while (dataFileReader.hasNext()) {
AvroRec = dataFileReader.next(AvroRec);
System.out.println(AvroRec);
}
}
public static void main(String[] args) throws JsonParseException, JsonProcessingException, IOException {
AvroExampleWithoutCodeGeneration AvroEx = new AvroExampleWithoutCodeGeneration();
AvroEx.serialize();
AvroEx.deserialize();
}
}
You can put this instead:
Schema schema = new Schema.Parser().parse.newFile("resources/StudentActivity.avsc");

ElasticSearch : Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available

I am trying to use the Java Bulk API for creating the documents in ElasticSearch. I am using a JSON file as the bulk input. When I execute, I get the following exception:
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: []]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:280)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:197)
at org.elasticsearch.client.transport.support.TransportProxyClient.execute(TransportProxyClient.java:55)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:272)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:347)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:85)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:59)
at bulkApi.test.App.main(App.java:92)
This is the java code.
package bulkApi.test;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) throws IOException, ParseException
{
System.out.println( "Hello World!" );
// configuration setting
Settings settings = Settings.settingsBuilder()
.put("cluster.name", "test-cluster").build();
TransportClient client = TransportClient.builder().settings(settings).build();
String hostname = "localhost";
int port = 9300;
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostname),port));
// bulk API
BulkRequestBuilder bulkBuilder = client.prepareBulk();
long bulkBuilderLength = 0;
String readLine = "";
String index = "testindex";
String type = "testtype";
String _id = null;
BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream("/home/nilesh/Shiney/Learn/elasticSearch/ES/test/parseAccount.json"))));
JSONParser parser = new JSONParser();
while((readLine = br.readLine()) != null){
// it will skip the metadata line which is supported by bulk insert format
if (readLine.startsWith("{\"index")){
continue;
}
else {
Object json = parser.parse(readLine);
if(((JSONObject)json).get("account_number")!=null){
_id = String.valueOf(((JSONObject)json).get("account_number"));
System.out.println(_id);
}
//_id is unique field in elasticsearch
JSONObject jsonObject = (JSONObject) json;
bulkBuilder.add(client.prepareIndex(index, type, String.valueOf(_id)).setSource(jsonObject));
bulkBuilderLength++;
try {
if(bulkBuilderLength % 100== 0){
System.out.println("##### " + bulkBuilderLength + "data indexed.");
BulkResponse bulkRes = bulkBuilder.execute().actionGet();
if(bulkRes.hasFailures()){
System.out.println("##### Bulk Request failure with error: " + bulkRes.buildFailureMessage());
}
bulkBuilder = client.prepareBulk();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
br.close();
if(bulkBuilder.numberOfActions() > 0){
System.out.println("##### " + bulkBuilderLength + " data indexed.");
BulkResponse bulkRes = bulkBuilder.execute().actionGet();
if(bulkRes.hasFailures()){
System.out.println("##### Bulk Request failure with error: " + bulkRes.buildFailureMessage());
}
bulkBuilder = client.prepareBulk();
}
}
}
Couple of things to check:
Check that your cluster name is same as the one defined in
elastic.yml
Try creating the index with the index name
('testindex' in your case) with PUT api from any REST Client
(ex:AdvancedRestClient) http://localhost:9200/testindex (Your
request has to be successful i.e status code==200 )
Run your program after you create the index with the above PUT request.

How to set the text color to my MIME message.setSubject() methods text content?

I have written a java code to send a mail.
I need to set the Email subject color,ie I need to set the color for the text of method message.setSubject().
Below are my codes :
package comparexmlf1;
import comparexmlf1.validatexml;
import comparexmlf1.CarParser1;
import comparexmlf1.OrderParser2;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream.GetField;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.Properties;
import java.util.logging.Logger;
import javax.lang.model.element.Element;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.swing.text.html.MinimalHTMLWriter;
import javax.xml.soap.MimeHeader;
import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
public class mailer {
static void sendmail() throws IOException,
MessagingException,AddressException
{
String to1=CarParser1.to1;
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy
HH:mm:ss");
Calendar cal = Calendar.getInstance();
String to2 = CarParser1.to2;
String to3= CarParser1.to3;
String to4=CarParser1.to4;
String from = CarParser1.from;
String host = CarParser1.host;
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
MimeMessage message = new MimeMessage(session);
int m_toterr,m_totwarn;
String getfilepath="";
String filenamechange="D:/newlog
/"+CarParser1.si_orderid+"_log.txt";
System.out.println("New File Path for mail:"+filenamechange);
String pathLogFile = filenamechange;
Enumeration enumeration =
CarParser1.logger.getRootLogger().getAllAppenders();
try {
m_toterr=validatexml.Total_err;
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress(to1));
message.setSubject("<html><head></head><body><h1><p
style=color:red> CAR Validation Report at :
"+dateFormat.format(cal.getTime())+" for the Order ID :
"+CarParser1.si_orderid+"</p></h1></body><html>","text/html"
);
StringBuffer sb = new StringBuffer();
FileInputStream fstream = new
FileInputStream(pathLogFile);
BufferedReader br = new BufferedReader(new
InputStreamReader(fstream));
String singleLine;
while ((singleLine = br.readLine()) != null)
{
sb.append(singleLine + "<br>");
}
br.close();
String allLines = sb.toString();
String allLines_html=" <html><head><title></title>
</head>"
+ "<body style=background-
color:skyblue;>"+allLines+"</body ></html>";
message.setContent(allLines_html, "text/html;
charset=ISO-8859-1");
Transport.send(message);
System.out.println("Email Sent successfully....");
CarParser1.logger.info("Email Sent Successfully...");
System.out.println();
}
catch (MessagingException mex)
{
System.out.println("Invalid Email Address.please provide
a valid email id to send with");
mex.printStackTrace();
}
}
}
Can anyone help me to achieve this task.
Thank you
There's no way to do that. The application that displays the message gets to choose how to display the Subject information, including what font and color to use. Unlike the body of the message, there's no way to supply "rich text" or html attributes for the Subject.

Trying to add an event to google places

I am trying to use the Google Place Actions API, specifically the events and I cannot get a valid post for the life of me.
Here is the URL I am using:
https://maps.googleapis.com/maps/api/place/event/add/json?sensor=false&key=placesApiKey&duration=26000&reference=CjQwAAAAv4TTQ3ySXiGhOElWFNAQ-roLOfgwo215yRTk1Bmhg0jSJ-sAdz9nHgNgnGBAmqP7EhC7K0AjTfFcZgCUh68c2yNtGhRkmynXvE5d4XA5ZfyBqAxlNdsAIg&summary=this is going to be something fun
The reference is to Tempe, AZ. I keep getting a 404 back saying that it is an illegal request. Any help would be great! I really don't know what I am doing wrong.
I have tried three different ways both with the same results:
HttpClient client = new HttpClient();
client.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
String url = "https://maps.googleapis.com/maps/api/place/event/add/json?sensor=false&key=" + googlePlacesAPIKey;
PostMethod post = new PostMethod(url);
NameValuePair[] data = {
new NameValuePair("duration", Long.toString(duration)),
new NameValuePair("reference", reference),
new NameValuePair("summary", summary)
};
post.setRequestBody(data);
and
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://maps.googleapis.com/maps/api/place/event/add/json?sensor=false&key=" + googlePlacesAPIKey);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("duration", Long.toString(duration)));
nameValuePairs.add(new BasicNameValuePair("reference", reference));
nameValuePairs.add(new BasicNameValuePair("summary", summary));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
}
and
URL url = new URL("https://maps.googleapis.com/maps/api/place/event/add/json?sensor=false&key="+googlePlacesAPIKey+"&duration="+duration+"&reference="+reference+"&summary="+summary);
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoOutput(true);
httpCon.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter( httpCon.getOutputStream());
System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage()); out.close();
and
HttpPost post = new HttpPost("https://maps.googleapis.com/maps/api/place/event/add/json?sensor=false&key=" + googlePlacesAPIKey);
post.setHeader("Content-type", "application/json");
JSONObject object = new JSONObject();
object.put("duration", Long.toString(duration));
object.put("reference", reference);
object.put("summary", summary);
String message = object.toString();
post.setEntity(new StringEntity(message));
HttpResponse response = client.execute(post);
Here is the link to the API for those that are curious:
https://developers.google.com/places/documentation/actions#event_add
In python, you can do like this:
#!/usr/bin/python
# coding: utf8
import sys
import urllib
parameters = urllib.urlencode({
'key' : "YOUR_API_KEY",
'sensor' : 'false'
})
url = "https://maps.googleapis.com/maps/api/place/event/add/json?%s" % (parameters)
#The reference
reference = "CoQBdgAAAN4u...YKmgQ"
#Add event
postdata = '''
{
"duration": 86400,
"language": "ja",
"reference": "%s",
"summary": "Event Name!",
"url" : "http://hogehoge.com/test_page"
}
''' % (reference)
f = urllib.urlopen(url, postdata)
print f.read()
Ok, I'm not good for Java though, I created an example code for Android Java.
[MainActivity.java]
package com.example.placeseventtest;
import org.json.JSONArray;
import org.json.JSONObject;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private final String API_KEY = "YOUR_API_KEY";
private PlacesHTTP myUtil;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView resTxtView = (TextView) findViewById(R.id.responseText);
myUtil = new PlacesHTTP(API_KEY, resTxtView);
Button currentPosBtn = (Button) this.findViewById(R.id.currentPosBtn);
currentPosBtn.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
JSONObject params = new JSONObject();
JSONObject location = new JSONObject();
JSONArray types = new JSONArray();
try {
location.put("lat", 123.4556);
location.put("lng", 123.4556);
params.put("location", location);
params.put("accuracy", 20);
params.put("name", "Event Name");
//only one type is available.
types.put("parking");
params.put("types", types);
params.put("language", "en");
} catch (Exception e) {}
// Show the request JSON data.
TextView reqTxtView = (TextView) findViewById(R.id.requestText);
try {
reqTxtView.setText(params.toString(2));
} catch (Exception e) {}
// POST to Google Server
myUtil.execute(params);
}
});
}
}
[PlacesHTTP.java]
package com.example.placeseventtest;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import android.os.AsyncTask;
import android.widget.TextView;
public class PlacesHTTP extends AsyncTask<JSONObject, Void, HttpResponse>{
private HttpPost post;
private HttpClient httpClient;
private String url;
private TextView txtView;
public PlacesHTTP(String api_key, TextView resultView) {
url = String.format("https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key=%s", api_key);
txtView = resultView;
}
protected void onPreExecute() {
httpClient = new DefaultHttpClient();
post = new HttpPost(url);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
}
#Override
protected HttpResponse doInBackground(JSONObject... params) {
//Send data as JSON format
JSONObject opts = params[0];
StringEntity strEntity;
HttpResponse response = null;
try {
strEntity = new StringEntity(opts.toString());
post.setEntity(strEntity);
response = httpClient.execute(post);
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
protected void onPostExecute(HttpResponse result) {
if (result != null) {
// Display the result
try {
txtView.setText(EntityUtils.toString(result.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
} else {
txtView.setText("null");
}
}
}
I got this result:

MySQL db connection

I have been searching the web for a connection between my Android simulator and a MySQL db.
I've found that you can't connect directly but can via a web server. The web server will handle my request from my Android.
I found the following code on Hello Android, but I don't understand. If I run this code on the simulator, nothing happens; the screen stays black.
Where does Log.i land, in the Android screen, the error log, or somewhere else?
Can somebody help me with this code?
package app.android.ticket;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class fetchData extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//call the method to run the data retreival
getServerData();
}
public static final String KEY_121 = "http://www.jorisdek.nl/android/getAllPeopleBornAfter.php";
public fetchData() {
Log.e("fetchData", "Initialized ServerLink ");
}
private void getServerData() {
InputStream is = null;
String result = "";
//the year data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year","1980"));
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(KEY_121);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//parse json data
try{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","id: "+json_data.getInt("id")+
", name: "+json_data.getString("name")+
", sex: "+json_data.getInt("sex")+
", birthyear: "+json_data.getInt("birthyear")
);
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
}
}
Logging messages go in the Log cat. You could also use LogCat Reader.