I'm new to android programming and am working on a simple app, which will have to perfom POST and GET operations. I have a JSON parser class which creates a http request, but I keep getting an error on 'GET'. I have spent some time now trying to debug that and I have re-written the code a couple of times (I have also found similar threads on SO, but the suggested solutions didn't work for me), but I still cannot figure out what is wrong, as I keep getting the same error.
Asked
Active
Viewed 104 times
2
-
if you send a GET request to the same URL using a browser or another program, do you get a properly formed JSON? – kit Apr 21 '16 at 13:07
-
Have you tried it using POST method?? – Aamir Apr 21 '16 at 13:21
-
first of all check you link, is it giving a correct response? – Newbiee Apr 21 '16 at 13:25
-
I haven't tried the POST method yet, as I wanted to fix GET first... And yes, the url works as it should! :/ – eee Apr 21 '16 at 13:40
2 Answers
3
you need to use .equals
instead of ==
to compare Strings in Java so you need to convert:
if(method == "GET")
to:
if(method.equals("GET"))

Pooya
- 6,083
- 3
- 23
- 43
-
thanks! unfortunately this didn't fix the problem - I still get the same error :/ – eee Apr 21 '16 at 13:11
-
-
@eee also in your switch(status) block, if there is another common error like (404, 500 , ...), then the json string will be "" which when you try to parse it, you will get an error – Pooya Apr 21 '16 at 13:17
-
Thanks, true, I didn't think about that, I've now deleted the switch statement, and moved the contents of it in another try/catch statement. I've edited the OP so it now contains the call of the method. – eee Apr 21 '16 at 13:40
-
-
3
As Pooya have said you need to use ".equals".
Moreover, to avoid some null pointer you can invert the check
if("GET".equals(method))

Farolink
- 57
- 7