我遵循教程中使用Retrofit Library将数据插入数据库的格式。 logcat显示错误Unable to create call adapter for retrofit2.Call<dagger.com.japorms.model.User_Account_Model> for method APIService.registerUser
这是我的APIService界面:
public interface APIService {
@FormUrlEncoded
@POST("test_db/register.php")
Call<User_Account_Model> registerUser(@Field("email") String email, @Field("password") String password);
}
以下是方法:
public void registerUser(){
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Registering Account");
progressDialog.setMessage("Please Wait ...");
progressDialog.setCancelable(false);
progressDialog.show();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://192.168.1.73:8080/")
.addConverterFactory(GsonConverterFactory.create())
.build();
APIService service = retrofit.create(APIService.class);
User_Account_Model user_account_model = new User_Account_Model();
user_account_model.email = reg_email_et.getText().toString();
user_account_model.password = reg_pass_et.getText().toString();
String conf_pass = reg_conf_pass_et.getText().toString();
if(user_account_model.password.equals(conf_pass)){
Call<User_Account_Model> call = service.registerUser(user_account_model.email,user_account_model.password);
call.enqueue((new Callback<User_Account_Model>() {
@Override
public void onResponse(Call<User_Account_Model> call, Response<User_Account_Model> response) {
progressDialog.dismiss();
}
@Override
public void onFailure(Call<User_Account_Model> call, Throwable t) {
}
}));
}
else
{
progressDialog.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(Html.fromHtml("<font color='#ff0000'>REGISTER FAILED</font>")).setMessage("password and confirm password did not match")
.setCancelable(false)
.setNegativeButton("Ok", null).create().show();
}
}
我的格式与教程相同,只是我有2个参数。我希望你能帮我解释这个logcat,因为我很难理解它,因为我是这个Retrofit库的新手。非常感谢你们。
答案 0 :(得分:0)
可以在这里粘贴User_Account_Model.class
您是否添加了应用程序gradle文件
compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'