I want to login in some service called vid.me,https://api.vid.me/oauth/authorize with POST.But when I try to get data from log I have NullPointerException.I tryed to make Toast and have this error too.I'm trying to get response code to see I did this 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) {
}
});
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…