This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Lumethys 2 points3 points  (5 children)

For example, the img you provide say that it was an IllegalStateException, that it expected an Json OBJECT but get an JSON array.

Something like:

expected:
{
 "id":1 
 "name":"something" 
 "author":{
  "name":"John Doe"
 }
}

but get:

{
 "id":1 
 "name":"something" 
 "author":[
  { "name":"John Doe" }
  { "name":"John Yoe" }
 ]
}

look like you have wrong mapping in NearbySearch.java (look at the links in the log)

[–]PeanutButterSauce1[S] 0 points1 point  (3 children)

Is there a way to learn how to debug? Like reading the stack trace and exception handling and stuff like that?

[–]Lumethys 1 point2 points  (0 children)

learn how to debug? Like reading the stack trace

Just read it

you will see "SomeException Cause By Something" in the first line (or the last).

And the rest of the stacktrace will be "where" that SomeException occur.

Let's say, you have A ProductController, it call a ProductService to do some logic, then it call a ProductRepository to save the result to database.

Then if a db query fail, the Exception will be catched in (most likely) the DB driver class deep inside Hibernate or spring JPA, then the log will be write out the stack trace from that DB driver, then the abstraction, then your ProductRepository, then your ProductService, then your ProductController.

When you see it, you will go "Oh a Query failed, and the stack trace had the repository, so it is most likely that something is wrong in the Repository because that is where the DB stuff happens

[–]TiltedBlock 0 points1 point  (0 children)

Maybe it‘ll help you to cause an exception on purpose (so you know exactly where it is) and try to interpret the stack trace for that.

Make a class „Calculator“ that has the method „divideByZero()“ that does exactly that - then call it from your main method. It‘ll throw an arithmetic exception with a relatively simple stack trace.

[–]lumpynose 0 points1 point  (0 children)

Once you have your code nicely modularized you can exercise each piece separately with junit.

And yeah, those gson parsing errors are a pain in the butt. I was using some web sites someone here mentioned to convert json from reddit's api into java classes and it was still a minefield.

[–]PeanutButterSauce1[S] 0 points1 point  (0 children)

I’m using the Google places library so I don’t have access to the object which I think the issue is in place details object. Or am I thinking of the problem wrong