• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Help with servlet, android

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am trying to do is get a String variable of JSONObject type from the android and then parse it into 4 different variables: lat, lon, start, end. Then use 2 JSONArrays and 2 int arrays, combine 2 int arrays into a JSONArray.Send this JSONarray to the android where it will be used to plot a graph. Somehow, the response is not getting delivered to the android. please help me.

The servlet code is like this:



The Android code is:



.....................} }
Any help would be highly appreciated. Thanks.
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Narrow it down.
Have you logged what's going on in the servlet so you can check it is actually being hit?
I can't see any logging in there.

Should the servlet work when accessed by the device then the next step is to debug that part of the Android code and log what is coming back.
Again, I don't see any logging (beyond stack traces).

Without some debugging logs to show you what is actually going on then you are flying blind. Staring at code and trying to spot an error is very inefficient compared to having solid data about what is going on inside your app.
 
Bartender
Posts: 7488
171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "the response is not getting delivered" mean, exactly? Which lines of code are or are not being executed on the server? Which lines of code are or are not being executed on the client? Are there any exceptions or other messages in either the server logs or the Android logcat?
 
jasmine franco
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Narrow it down.
Have you logged what's going on in the servlet so you can check it is actually being hit?
I can't see any logging in there.

Should the servlet work when accessed by the device then the next step is to debug that part of the Android code and log what is coming back.
Again, I don't see any logging (beyond stack traces).

Without some debugging logs to show you what is actually going on then you are flying blind. Staring at code and trying to spot an error is very inefficient compared to having solid data about what is going on inside your app.



I don't know how to actually log. I see a log file in the apache tomcat folder but I don't understand much of it.
 
jasmine franco
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:What does "the response is not getting delivered" mean, exactly? Which lines of code are or are not being executed on the server? Which lines of code are or are not being executed on the client? Are there any exceptions or other messages in either the server logs or the Android logcat?



The below part of code in Servlet is supposed to provide values in private void setUpGraph() in Android code to these variables : private Number[] time = new Number[9] {};private Number[] noise = new Number[9] .
sentString in servlet should be received at the android end, but it just consider the default values of private Number[] time = new Number[9] {};private Number[] noise = new Number[9] instead of int[] timeUnix = {1423502074, 1423588474, 1423674874, 1423761274, 1423847674, 1423934074, 1424020474, 1424106874, 1424193274};
int [] db = {1000,2030,3930,4030,5030,6300,7300,8300,9380};
int[] timeResult = new int[9];
int[] dbResult = new int[9];
in the servlet.


 
Greenhorn
Posts: 11
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I don't know how to actually log. I see a log file in the apache tomcat folder but I don't understand much of it.



You can use android.util.Log;

then you can Log out messages with Log.i / Log.e etc depending on what level you want.

for example to log an error from an Exception.



Of course you can use this anywhere in your code to log things. The advantage in this over System.out.print is that the Logs colour the messages, making them easier to spot in the Trace, and have extra functionality if needed.

With that in mind, you could also test your servlet in the browser using something like POSTMAN for chrome, which is an excellent free plugin or REST requests. You could even use Chrome dev tools since they are also an excellent resource. Either way you need to see the response you are getting from your server hosting the servlet, it will tell you a lot about whats happening. E.g. if the response code is 404, 500 etc.
 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic