This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

JSON Object Error  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm using a friends code to help connect my app to my SQL database. However the app is stopping at a certain point. I know this because of the comments I have added.

I'd appreciate if somebody could help me and advice on how to fix it.



I'm getting to the Log 6.2 but I'm not getting Log 6.3, so I'm presuming the error is on line 4 above.

Thanks,
 
Saloon Keeper
Posts: 2470
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Harry Burke wrote:I'm getting to the Log 6.2 but I'm not getting Log 6.3, so I'm presuming the error is on line 4 above.


What is the value of response which is logged in line 2?

Does logcat show any exceptions raised for line 4?
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:

Harry Burke wrote:I'm getting to the Log 6.2 but I'm not getting Log 6.3, so I'm presuming the error is on line 4 above.


What is the value of response which is logged in line 2?

Does logcat show any exceptions raised for line 4?



Hi,

The value of 'response' in line 2 is the word -> connected.

No LogCat doesn't give anything back for line 4 unfortunately.

Thanks
 
Ron McLeod
Saloon Keeper
Posts: 2470
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:What is the value of response which is logged in line 2?


Harry Burke wrote:The value of 'response' in line 2 is the word -> connected.


connected is not a valid JSON representation, so it is most likely throwing an exception (which you should see in the logcat log).

Simple test:
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:
connected is not a valid JSON representation, so it is most likely throwing an exception (which you should see in the logcat log).

Simple test:




No I'm not getting any Information back from LogCat for 6.3.... would you know how I could possibly fix this?

Thanks
 
Ron McLeod
Saloon Keeper
Posts: 2470
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is expecting responseBody to be a JSON representation, but  it is not, so trying to parse it as JSON fails.  The fix to make that responseBody actually JSON.

Where does the contents responseBody some from?
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:Where does the contents responseBody some from?



Here's the full function. This is the only place where "responsebody" is.

 
Ron McLeod
Saloon Keeper
Posts: 2470
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Harry Burke wrote:


It looks like this method is a handler for a response from a web service.

Make sure that you are asking for a JSON-formatted response in the request (Accept: application/json header).
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:
It looks like this method is a handler for a response from a web service.

Make sure that you are asking for a JSON-formatted response in the request (Accept: application/json header).



Sorry to be basic at this but how would I go about doing that?

I appreciate your help!
 
Ron McLeod
Saloon Keeper
Posts: 2470
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The issue will be in the code which is performing the request to the server and receiving the response (or possibly with the server itself).  If you can, please post the code here (be sure to obfuscate any credentials or URLs which might be confidential).

Now that you have posted more code, we can see that your code is expecting that the server will provide a response with content which looks like this:
but from your logging, it appears like the response looks like this:
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the LoginActivity.java page. The login form on the app is filled in, then it goes to a login.php page to see if it's in the database.

It's just that I don't understand JSON well enough to figure out the error I'm having.

 
Ron McLeod
Saloon Keeper
Posts: 2470
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try this to specify to the server what type of response payload you want:
If that doesn't address the issue, then you may need to check the server side to get its perspective on what is happening.
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately that didn't solve the issue, I'm still getting to the same point as before.

Would you have any other idea that I could possibly use?

Thanks

(Sorry about the delay in this response)
 
Rancher
Posts: 3983
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might have missed it, but are you actually getting an exception with stack trace in your logs?
I noticed you are using e.printStackTrace() in your catch blocks.  Since you have a proper logging framework I would suggest replacing those with Log.e(LOG_TAG, "Some message", e).
 
Harry Burke
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have attached a picture of the error message that is now coming up in the LogCat.

Would anyone be able to let me know how I could go about fixing it?

Thanks
code.PNG
[Thumbnail for code.PNG]
 
Dave Tolls
Rancher
Posts: 3983
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Ron has said, though.
That is simply not a JSON string, and that's why it's complaining.

Are you sure you should be getting JSON back from the call you made?
It looks to me like you're just logging into somewhere, and the response is simply saying you're connected.

(Also, it's easier for us here if you can copy/paste the errors rather than showing a screenshot)
 
What are you doing? You are supposed to be reading this tiny ad!
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!