Android 改造错误应为BEGIN_对象,但在第1行第1列为字符串

Android 改造错误应为BEGIN_对象,但在第1行第1列为字符串,android,retrofit,Android,Retrofit,我试图解决这个错误,但找不到任何解决方案来解决我的问题,因为我已经尝试了所有给定的链接,这就是为什么我来这里 我正在尝试注册用户,但无法注册。请帮助我,因为这个问题已经占用了我一整天的时间。提前谢谢 我的ApiClient.Java在这里 public class ApiClient { private static final String BASE_URL = "http://IPAdress/foldername/"; private static Retrofi

我试图解决这个错误,但找不到任何解决方案来解决我的问题,因为我已经尝试了所有给定的链接,这就是为什么我来这里

我正在尝试注册用户,但无法注册。请帮助我,因为这个问题已经占用了我一整天的时间。提前谢谢

我的ApiClient.Java在这里

    public class ApiClient {

    private static final String BASE_URL = "http://IPAdress/foldername/";
    private static Retrofit retrofit = null;

   private static Gson gson = new GsonBuilder()
            .setLenient()
            .create();

    public static Retrofit getApiClient(){

        if (retrofit==null){
            retrofit=new Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .build();
        }
        return retrofit;
    }
User.Java类

public class User {

@SerializedName("response")
private String Response;

@SerializedName("name")
private String Name;

public String getResponse() {
    return Response;
}

public String getName() {
    return Name;
}
main活动

public static SessionManager sessionManager;

EditText Name, Email, Password;
Button btn_register, btn_login;

String name, email, password;

Boolean CheckEditText;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    sessionManager = new SessionManager(this);

    //if the user is already logged in we will directly start the Profile Fragment
    if (sessionManager.readLoginStatus()) {
        startActivity(new Intent(this, ProfileFragment.class));
        finish();
    }
    Name = findViewById(R.id.username);
    Email = findViewById(R.id.useremail);
    Password = findViewById(R.id.userpassword);
    btn_register = findViewById(R.id.btnRegister);
    btn_login = findViewById(R.id.btnLinkToLoginScreen);

    btn_register.setOnClickListener(v -> {
        CheckEditTextIsEmptyOrNot();
        if (CheckEditText) {
            registration();
        } else {
            Toast.makeText(RegisterActivity.this, "Please fill all form fields.", Toast.LENGTH_SHORT).show();
        }
    });

    btn_login.setOnClickListener(v -> {
        Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
        startActivity(intent);
    });
}

public void CheckEditTextIsEmptyOrNot() {

    name = Name.getText().toString().trim();
    email = Email.getText().toString().trim();
    password = Password.getText().toString().trim();

    // Checking whether EditText value is empty or not.
    // If any of EditText is empty then set variable value as False.
    // If any of EditText is filled then set variable value as True.
    CheckEditText = !TextUtils.isEmpty(name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(password);
}


private void registration() {

    ApiInterface apiInterface = ApiClient.getApiClient().create(ApiInterface.class);
    Call<User> call = apiInterface.performRegistration(name, email, password);
    call.enqueue(new Callback<User>() {
        @Override
        public void onResponse(@NonNull Call<User> call, @NonNull Response<User> response) {

            assert response.body() != null;
            switch (response.body().getResponse()) {
                case "ok":
                    RegisterActivity.sessionManager.displayToast("Registration Success...");
                    break;
                case "exist":
                    RegisterActivity.sessionManager.displayToast("User Already Exist...");
                    break;
                case "error":
                    RegisterActivity.sessionManager.displayToast("Something Went Wrong...");
                    break;
            }
        }

        @Override
        public void onFailure(@NonNull Call<User> call, @NonNull Throwable t) {

            Log.d("onFailure", t.toString());
            Toast.makeText(RegisterActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });
公共静态会话管理器SessionManager;
编辑文本名称、电子邮件、密码;
按钮btn_注册,btn_登录;
字符串名称、电子邮件、密码;
布尔校验文本;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u寄存器);
sessionManager=新的sessionManager(this);
//如果用户已经登录,我们将直接启动配置文件片段
if(sessionManager.readLoginStatus()){
startActivity(新意图(这个,ProfileFragment.class));
完成();
}
Name=findviewbyd(R.id.username);
Email=findviewbyd(R.id.useremail);
Password=findviewbyd(R.id.userpassword);
btn_寄存器=findViewById(R.id.btnRegister);
btn_login=findviewbyd(R.id.btnLinkToLoginScreen);
btn_register.setOnClickListener(v->{
CheckEditTextIsEmptyOrNot();
如果(检查编辑文本){
注册();
}否则{
Toast.makeText(RegisterActivity.this,“请填写所有表单字段”,Toast.LENGTH\u SHORT.show();
}
});
btn_login.setOnClickListener(v->{
Intent Intent=新的Intent(getApplicationContext(),LoginActivity.class);
星触觉(意向);
});
}
公共无效CheckEditTextIsEmptyOrNot(){
name=name.getText().toString().trim();
email=email.getText().toString().trim();
password=password.getText().toString().trim();
//检查EditText值是否为空。
//如果任何EditText为空,则将变量值设置为False。
//如果任何EditText已填充,则将变量值设置为True。
CheckEditText=!TextUtils.isEmpty(名称)和&!TextUtils.isEmpty(电子邮件)和&!TextUtils.isEmpty(密码);
}
私人无效登记(){
ApiInterface ApiInterface=ApiClient.getApiClient().create(ApiInterface.class);
Call Call=apinterface.performRegistration(姓名、电子邮件、密码);
call.enqueue(新回调(){
@凌驾
public void onResponse(@NonNull调用,@NonNull响应){
assert response.body()!=null;
开关(response.body().getResponse()){
案例“ok”:
RegisterActivity.sessionManager.displayToast(“注册成功…”);
打破
案例“存在”:
RegisterActivity.sessionManager.displayToast(“用户已存在…”);
打破
案例“错误”:
RegisterActivity.sessionManager.displayToast(“出现了问题…”);
打破
}
}
@凌驾
public void onFailure(@NonNull Call Call,@NonNull Throwable t){
Log.d(“onFailure”,t.toString());
Toast.makeText(RegisterActivity.this,t.getMessage(),Toast.LENGTH_SHORT.show();
}
});

创建这样的类

public class MyResponse {
  @SerializedName("response")
  private String response;
  //Constructor
  //GET and SET
}

然后,您的服务应该返回一个
调用
,然后在您执行操作时检查主体,它应该会工作。

我是否要将该
调用
更改为
调用
?>也很高兴知道您期望的json以及您发送的数据。我已经使用我创建的技术用json数据图像更新了这个问题MyResponse clas,然后将
Call
更改为
Call
。在此之后,我在
开关(response.body().getResponse())
部分出错。getResponse
中显示了
找到的所需字符、字节、短字符、int不兼容类型