android - NPE error using Retrofit -
i want login in service called vid.me,https://api.vid.me/oauth/authorize post.but when try data log have nullpointerexception.i tryed make toast , have error too.i'm trying response code see did right or no.
my api class:
public interface videoapi { @get("/videos/featured") call<videos> getfeaturedvideo(); @get("/videos/new") call<videos> getnewvideo(); @formurlencoded @post("oauth/authorize") call<signinresults>insertuser(@field("name") string name, @field("password") string password ); }
my fragment:
public class feedfragment extends fragment { edittext username; edittext password; button btnlogin; public list<signinresult> signinresult; public static final string root_url = "https://api.vid.me/"; public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_feed, container, false); username = (edittext) rootview.findviewbyid(r.id.user_name_field); password = (edittext) rootview.findviewbyid(r.id.password_field); btnlogin = (button)rootview.findviewbyid(r.id.button_login); btnlogin.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { authorize(); } }); return rootview; } public void authorize(){ retrofit retrofitadapter = new retrofit.builder() .addconverterfactory(gsonconverterfactory.create()) .baseurl(root_url) .build(); final videoapi videoapi = retrofitadapter.create(videoapi.class); call<signinresults> call = videoapi.insertuser(username.gettext().tostring(),password.gettext().tostring()); call.enqueue(new callback<signinresults>() { @override public void onresponse(call<signinresults> call, response<signinresults> response) { log.d("feedfragment", "status code = " + response.body().signinresults.get(0).getcode()); } @override public void onfailure(call<signinresults> call, throwable t) { } }); } }
call<signinresponse> call = videoapi.insertuser(username_value, password_value); call.enqueue(new callback<signinresponse>() { @override public void onresponse(call<signinresponse> call, response<signinresponse> response) { signinresponse results = response.body(); log.d("response ==>> ", new gsonbuilder().setprettyprinting().create().tojson(results)); } @override public void onfailure(call<signinresponse> call, throwable t) { } }); @headers("content-type:application/x-www-form-urlencoded") @formurlencoded @post("/auth/create") call<signinresponse> insertuser(@field("email") string username, @field("password") string password );
Comments
Post a Comment