0
我试着通过改造library.But摆脱onResponse方法数据现在我有==输入反应0。I neew让我的请求的代码,在我的app.For例如,如果建立逻辑代码== 200,启动新的活动是别的东西建立错误消息。 我试图建立正确的POST方法vid.me servise.That服务具有开放的API,方法我需要什么: https://docs.vid.me/#api-Auth-Create myFragment:NPE在onResponse方法利用改造
public class FeedFragment extends Fragment {
EditText username;
EditText password;
Button btnLogin;
public List<SignInResult> signInResult;
String username_value,password_value;
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);
username_value = username.getText().toString();
password_value = password.getText().toString();
Call<SignInResults> call = videoApi.insertUser(username_value,password_value);
call.enqueue(new Callback<SignInResults>() {
@Override
public void onResponse(Call<SignInResults> call, Response<SignInResults> response) {
SignInResults results = response.body();
Log.d("Response ==>> ", new GsonBuilder().setPrettyPrinting().create().toJson(results));
}
@Override
public void onFailure(Call<SignInResults> call, Throwable t) {
}
});
}
}
API接口:
public interface VideoApi {
@GET("/videos/featured")
Call<Videos> getFeaturedVideo();
@GET("/videos/new")
Call<Videos> getNewVideo();
@Headers("Content-Type:application/x-www-form-urlencoded")
@FormUrlEncoded
@POST("/auth/create")
Call<SignInResults>insertUser(@Field("email") String username,
@Field("password") String password
);
}
SignInResult类:
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) {
this.username = username;
}
@SerializedName("username")
@Expose
private String username;
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
@SerializedName("user_id")
@Expose
private String user_id;
}
个
SignInResults类:
public class SignInResults {
public SignInResult signInResult;
public List<SignInResult> getSignInResults() {
return signInResults;
}
List<SignInResult> signInResults;
}
你能提供NPE异常堆栈跟踪? – nnesterov