将我的改装gradle文件从beta2更新到当前的beta4后,目前遇到了问题。我收到标题中显示的错误,但是,这个@POST方法之前有效,但目前还没有在更新后工作,我无法完全理解出错的地方。在此先感谢您的帮助。
public interface UserApi {
String baseUrl = "some url";
@POST("users")
Call<User> postJson(@Body User user);
class Factory{
private static UserApi service;
public static UserApi getInstance(){
if(service == null){
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(baseUrl).build();
service = retrofit.create(UserApi.class);
return service;
}else{
return service;
}
}
}
}
public class RegisterActivity extends AppCompatActivity {
@Bind(R.id.register_password) EditText mPass;
@Bind(R.id.confirm_password) EditText mConfirm;
@Bind(R.id.register_firstName) EditText mFirstName;
@Bind(R.id.register_lastName) EditText mLastName;
@Bind(R.id.register_email) EditText mEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
ButterKnife.bind(this);
}
@OnClick(R.id.register_button)
public void Registration() {
if (!(mPass.getText().toString().equals(mConfirm.getText().toString()))) {
Toast.makeText(getBaseContext(), "Passwords Do Not Match", Toast.LENGTH_LONG).show();
} else if (mPass.getText().toString().isEmpty()) {
Toast.makeText(getBaseContext(), "Password Field is Blank, Enter a Valid Password", Toast.LENGTH_LONG).show();
}else{
String password = mPass.getText().toString();
String confirmPass = mConfirm.getText().toString();
String firstName = mFirstName.getText().toString();
String lastName = mLastName.getText().toString();
String email = mEmail.getText().toString();
User user = new User(firstName, lastName, email, password);
UserApi.Factory.getInstance().postJson(user).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
Log.v("Did it work? ", "Yes it did work");
}
@Override
public void onFailure(Call<User> call, Throwable t) {
Log.v("No Dice", t.getMessage());
}
});
Intent login = new Intent(this, MainActivity.class);
startActivity(login);
}
}
}
错误:
02-24 20:51:53.340 16889-16889/com.example.android.todotracker V/No Dice: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $