last day (14 days later) » 

12:16 PM
0
A: Trying to get data for POST method Retrofit

Prashant MSignInResults.java // Model class clas SignInResults { public Boolean status; public Auth auth; public User user; } User.java //User Model public class User { public String userId; public String username; public String avatar; } checkout this code in onResponse function...

 
I put this code to onResponse and have the same error in second line SignInResults result = response.body(); String result_username = result.getUsername();
 
public String username; ==>> username key should be the same as the backend returns. If backend is returning user_name then it will be null always when you access username.
 
backend have username value docs.vid.me/#api-Auth-Create here is documentation,its seems easy
 
Ok. So to debug more. you can add Gson library in your gradle "com.google.code.gson:gson:${gsonVersion}". and use the following statement to print the whole json. ==>> Timber.i(new GsonBuilder().setPrettyPrinting().create().toJson(results)); Check whether the actual value is getting in the response or not.
I am using timber. You can use Log.d("Results ==>> ",new GsonBuilder().setPrettyPrinting().create().toJson(results) );
Hey wait. your response object is little bit different, that's why it is null always. I got the issue
I will update the answer. till please wait.
Please see my updated answer. I have added one more model class for user. I hope this time it should work now.
Please let me know if you got or not.
 
thank you,I check it now
it dont work's too:(
 
12:17 PM
Hi. Are you there? I am on chat room.
I may help you in more detail.
reply here once you are available online.
 
12:33 PM
Hey!
Yes,I'm here
 
actually I saw the response sample on the docs which you provided.
and it should work
Can you show your code? so that I can help more.
 
Yes,of course
thank for help,Im very appreciate this
my SignInResult class:
public class SignInResult {
public String getAuthorization() {
return authorization;
}

public void setAuthorization(String authorization) {
this.authorization = authorization;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

@SerializedName("authorization")
@Expose
private String authorization;
@SerializedName("code")
@Expose
private String code;

public String getUsername() {
return username;
}

public void setUsername(String username) {
and I have SignInResults class:
public class SignInResults {
public SignInResult signInResult;

public List<SignInResult> getSignInResults() {
return signInResults;
}

List<SignInResult> signInResults;
}
this class I put into <>
 
Are you using setters and getters methods? or just declared?
excluding username are you able to get the other values?
are you writing the app from scratch?
 
12:48 PM
I add getters and setters
no,Im try tu get other values but get NPE too
 
Can you please start the debugger and add a breakpoint where the NPE is throwing up.
see the nested object on response method.
let me know when you are done with this step.
 
Okay,few minutes please
 
Sure.
 
code 400 bad request(
body = {OkHttpCall$NoContentResponseBody@830023386408}
cacheControl = null
cacheResponse = null
request = {Request@830024545504} "Request{method=POST, url=https://api.vid.me/auth/create, tag=Request{method=POST, url=https://api.vid.me/auth/create, tag=null}}"
handshake = {Handshake@830025387808}
headers = {Headers@830024520568} "Content-Type: application/json\nDate: Mon, 25 Apr 2016 12:59:49 GMT\nServer: nginx\nSet-Cookie: rid=5b6d76d16a2e4b64b8e1389422b37319; expires=Sat, 17-May-2031 01:48:34 GMT; Max-Age=475159725; path=/; domain=vid.me\nSet-Cookie: srid=frACyTReTbefXzqSuGQKkg-IggcXQ-KPkr
 
1:14 PM
if your code >= 200 && code < 300 then only it will enter into onresponse method
otherwise it will go to onError method
so basically it is not going into your onresponse method
Since code is 400 bad request it will never go into onResponse
you are not able to login first of all
first you need to login successful then only the onResponse will execute.
let me know if anything required.
 
1:26 PM
I dont know what required and how to build succesfull request
 
1:42 PM
Hey are you there?
set the content type to application/x-www-form-urlencoded;
instead of sending the params which you were sending earlier
send like this
identity=email_id&password=my_password
you will get the login info
I tried and received successful
you may try with identity and email also
 
Yes,Im here
 
both will work
 
I dont understand how U can set content type
I
not U
How can I do this in android code?
 
Ok. wait
telling
 
thanks
 
1:53 PM
@Headers("Content-Type: application/x-www-form-urlencoded")
@FormUrlEncoded
@POST("/auth/create")
Call<SignInResults>insertUser(@Field("username") String username,
@Field("password") String password
);
You see at the top of last comment I have used @Headers
This how you can set the headers
Try it and let me know.
 
okay,thanks
few minutes
 
Sure.
 
I add this but still have NPE in my app(
 
Ok.
that is the other problem
that we can fix later on
you are not able to login first
you need to login
are you able to login sucessful first
?
are you able to get into onResponse method?
 
I get this again
rawResponse = {Response@830023789256} "Response{protocol=http/1.1, code=400, message=Bad Request, url=https://api.vid.me/auth/create}"
body = {OkHttpCall$NoContentResponseBody@830023730584}
cacheControl = null
cacheResponse = null
request = {Request@830023315568} "Request{method=POST, url=https://api.vid.me/auth/create, tag=Request{method=POST, url=https://api.vid.me/auth/create, tag=null}}"
handshake = {Handshake@830023512056}
headers = {Headers@830023789312} "Content-Type: application/json\nDate: Mon, 25 Apr 2016 13:58:27 GMT\nServer: nginx\nSet-Cookie: rid=d166a1a91da847
when I try to debug this
 
2:00 PM
Again you got 400 bad request
you should get 200 code
instead of 400
I think you are doing something wrong.
Is you code base too much big?
if not is it possible to share it with me so that I can quickly fix your problem.
 
no,my code is like I send in my question
 
if possible only.
Ok.
that code isn't sufficient
because the question was you were getting NPE
but the problem is totally different
you can't successfully login into the system
 
I understand it only now
 
now this is your actual problem
hmmm
is it possible you to create a sample project and keep only the code which you posted here
so that I can modify it and send it back to you in working condition
you may send me privately on my mail id also
 
Sure,few minutes
 
2:05 PM
Ok.
that will be very easy for me to debug and find the root cause
mail id is more.p.prashant@gmail.com
once sent just intimate me here
I am logged in with my company account but i cannot share that with you.
 
okay,I create simple project and send it for you but it will take 10 minute,okay?
 
Sure.
 
2:24 PM
I send you my project for your email
but that has "ra" change for "rar",gmail doesnt exist to send "rar" files
 
ok.
downloaded.
 
very big thanks for help)
 
3:26 PM
Hey there?
 
yes
How I can be offline if you help me)
 
hmmmm
your issue is fixed.
just was giving final touch
actually the project you sent me has many issue
 
oh,its very great news!
 
like there was no internet permission
 
what the main?
 
3:29 PM
gradle files were missing
so took moretime
 
I'm sorry,its my fault.I try to make it faster(
 
NP.
took 5 mins to manage missing dependencies only
uploading proj
actually the backend doesn't support param username
for login
its email instead of username
are you working closely with backend team
?
or trying to access the open APIs
?
 
hm,its strange.API documentation has "username" field
try to access open API
 
Ok.
 
its task for work
 
3:34 PM
so are you working in different company? right?
 
hm,I'm now working,its exam task for junior android
not working
 
Ok.
Just now I have replied to your email with working code.
I am sending this post link as reference to your posted questions
below are your asked links
http://stackoverflow.com/questions/36825234/npe-error-using-retrofit

http://stackoverflow.com/questions/36832385/npe-try-to-login-at-web-service

http://stackoverflow.com/questions/36837967/trying-to-get-data-for-post-method-retrofit

http://stackoverflow.com/questions/36842140/request-code-400-trying-to-login-into-webservice

http://stackoverflow.com/questions/36826948/npe-through-restrofit-post-method

http://stackoverflow.com/questions/36824539/post-in-retrofit\
 
Okay)
 
Please mark them as accepted answer
I hope you will do.
right?
 
of course)
where you posted the answer,I cant see(
 
3:47 PM
once answer can be post on inteval of only 2 mins
so will take time
you may accept once it is answered
 
okay
 
Here are the remaining unaccepted answers
http://stackoverflow.com/questions/36842140/request-code-400-trying-to-login-into-webservice/36845395#36845395

http://stackoverflow.com/questions/36826948/npe-through-restrofit-post-method/36845440#36845440

http://stackoverflow.com/questions/36824539/post-in-retrofit/36845491#36845491
 
accepted all)
thank you!You really help me
 
1
Q: Trying to get data for POST method Retrofit

pr RostIm trying to get username when I try to login to wev service.I need this username to check did I this right or no.But have NPE when try to get data,but when I just make Toast without data,it works!onResponse work,but I must to get code of this operation to build logic of my app.For example if my ...

This one is not accepted
 
now thats all accepted)
 
4:00 PM
yep.
Please feel free to post questions
 

last day (14 days later) »