简体   繁体   中英

java.lang.illegalStateException:Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $ Rest api Gives OnFailed

my json response

{
    "error": 200,
    "message": "New Admin",
    "adminUser": [
        {
            "adminUserId": "9",
            "adminUserGmail": "sagevadiyagulabadada123",
            "companyName": "",
            "name": "",
            "signUpDate": "2020-12-12",
            "expiryDate": "2020-12-12",
            "mobileNumber": "70465524937",
            "phoneNumber": "7065424937",
            "subscriptionPlan": "free",
            "profilePicPath": "image path",
            "gstNumber": "24AADSA5640A1Z3",
            "companyBillingAddress": "Guajrat India",
            "companyShippingAddress": "Gujarat India"
        }
    ]
}

MY CALL

    @Headers("Content-Type: application/json")
    @FormUrlEncoded
    @POST("insertAdmin.php")
    Call<GetLogInResponse> loginAdmin(
            @Field("adminUserGmail") String adminGmail,
            @Field("companyName") String companyName,
            @Field("name") String name,
            @Field("signUpDate") String signUpDate,
            @Field("expiryDate") String expiryDate,
            @Field("mobileNumber") String mobileNumber,
            @Field("phoneNumber") String phoneNumber,
            @Field("subscriptionPlan") String subPlan,
            @Field("profilePicPath") String profilePicPath,
            @Field("gstNumber") String gstNumber,
            @Field("companyBillingAddress") String billingAddress,
            @Field("companyShippingAddress") String shippingAddress
    );

i am calling like this

            Call<GetLogInResponse> call = RetrofitMain
                    .getRetrofitMain()
                    .getApis()
                    .loginAdmin(mail,
                            " ",
                            firebaseUser.getDisplayName(),
                            todayDate,
                            expiryDate,
                            " ",
                            " ",
                            "Free Trails",
                            " ",
                            " ",
                            " ",
                            " ");

            call.enqueue(new Callback<GetLogInResponse>() {
                @Override
                public void onResponse(Call<GetLogInResponse> call, Response<GetLogInResponse> response) {

                    GetLogInResponse logInResponse = response.body();
                    if (response.isSuccessful()){
                        switch (logInResponse.getMessage()) {

                            case "Already Exist": {

                                Toast.makeText(AdminLogin.this, "Already Exist.", Toast.LENGTH_LONG).show();
                                AdminUser adminUser = logInResponse.getAdminUser().get(0);
                                setData(adminUser);
                                sendUserToHome();
                                break;
                            }
                            case "New Admin": {
                                Toast.makeText(AdminLogin.this, "New Admin", Toast.LENGTH_LONG).show();
                                AdminUser adminUser = logInResponse.getAdminUser().get(0);
                                setNewData(adminUser);
                                sendUserToHome();

                                break;
                            }
                            case "Login Failed Try Again":
                                Toast.makeText(AdminLogin.this, "Login Failed!!! Try Again.", Toast.LENGTH_LONG).show();
                                break;
                        }
                    }else {
                        Toast.makeText(AdminLogin.this, "Login Failed!!! Try Again.", Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onFailure(Call<GetLogInResponse> call, Throwable t) {
                    Toast.makeText(AdminLogin.this, "Error" + t.getLocalizedMessage() + "  ++ "+ t.getMessage(), Toast.LENGTH_LONG).show();
                }
            });


        }else {
            Toast.makeText(AdminLogin.this, "Authentication Failed", Toast.LENGTH_LONG).show();
            startActivity(new Intent(AdminLogin.this, LogInActivity.class));
            finish();
        }

my model object AdminUser

public class AdminUser {

    @SerializedName("adminUserId")
    @Expose
    private String adminUserId;
    @SerializedName("adminUserGmail")
    @Expose
    private String adminUserGmail;
    @SerializedName("companyName")
    @Expose
    private String companyName;
    @SerializedName("name")
    @Expose
    private String name;
    @SerializedName("signUpDate")
    @Expose
    private String signUpDate;
    @SerializedName("expiryDate")
    @Expose
    private String expiryDate;
    @SerializedName("mobileNumber")
    @Expose
    private String mobileNumber;
    @SerializedName("phoneNumber")
    @Expose
    private String phoneNumber;
    @SerializedName("subscriptionPlan")
    @Expose
    private String subscriptionPlan;
    @SerializedName("profilePicPath")
    @Expose
    private String profilePicPath;
    @SerializedName("gstNumber")
    @Expose
    private String gstNumber;
    @SerializedName("companyBillingAddress")
    @Expose
    private String companyBillingAddress;
    @SerializedName("companyShippingAddress")
    @Expose
    private String companyShippingAddress;

    public String getAdminUserId() {
        return adminUserId;
    }

    public void setAdminUserId(String adminUserId) {
        this.adminUserId = adminUserId;
    }

    public String getAdminUserGmail() {
        return adminUserGmail;
    }

    public void setAdminUserGmail(String adminUserGmail) {
        this.adminUserGmail = adminUserGmail;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSignUpDate() {
        return signUpDate;
    }

    public void setSignUpDate(String signUpDate) {
        this.signUpDate = signUpDate;
    }

    public String getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(String expiryDate) {
        this.expiryDate = expiryDate;
    }

    public String getMobileNumber() {
        return mobileNumber;
    }

    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getSubscriptionPlan() {
        return subscriptionPlan;
    }

    public void setSubscriptionPlan(String subscriptionPlan) {
        this.subscriptionPlan = subscriptionPlan;
    }

    public String getProfilePicPath() {
        return profilePicPath;
    }

    public void setProfilePicPath(String profilePicPath) {
        this.profilePicPath = profilePicPath;
    }

    public String getGstNumber() {
        return gstNumber;
    }

    public void setGstNumber(String gstNumber) {
        this.gstNumber = gstNumber;
    }

    public String getCompanyBillingAddress() {
        return companyBillingAddress;
    }

    public void setCompanyBillingAddress(String companyBillingAddress) {
        this.companyBillingAddress = companyBillingAddress;
    }

    public String getCompanyShippingAddress() {
        return companyShippingAddress;
    }

    public void setCompanyShippingAddress(String companyShippingAddress) {
        this.companyShippingAddress = companyShippingAddress;
    }

}

my model object response

public class GetLogInResponse {

    @SerializedName("error")
    @Expose
    private int error;
    @SerializedName("message")
    @Expose
    private String message;
    @SerializedName("adminUser")
    @Expose
    private List<AdminUser> adminUser = null;

    public int getError() {
        return error;
    }

    public void setError(int error) {
        this.error = error;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<AdminUser> getAdminUser() {
        return adminUser;
    }

    public void setAdminUser(List<AdminUser> adminUser) {
        this.adminUser = adminUser;
    }
}

my error shows in toast like this java.lang.illegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

java.lang.illegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

what shoud i do? Thanks For Your Help.

log

    <b>Notice</b>:  Undefined index: adminUserGmail in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>9</b><br />
    <br />
    <b>Warning</b>:  mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>14</b><br />
I/okhttp.OkHttpClient: <br />
    <b>Notice</b>:  Undefined index: companyName in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>30</b><br />
    <br />
    <b>Notice</b>:  Undefined index: name in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>31</b><br />
    <br />
    <b>Notice</b>:  Undefined index: signUpDate in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>32</b><br />
    <br />
    <b>Notice</b>:  Undefined index: expiryDate in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>33</b><br />
    <br />
    <b>Notice</b>:  Undefined index: mobileNumber in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>34</b><br />
    <br />
    <b>Notice</b>:  Undefined index: phoneNumber in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>35</b><br />
    <br />
    <b>Notice</b>:  Undefined index: subscriptionPlan in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>36</b><br />
    <br />
    <b>Notice</b>:  Undefined index: profilePicPath in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>37</b><br />
    <br />
    <b>Notice</b>:  Undefined index: gstNumber in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>38</b><br />
    <br />
    <b>Notice</b>:  Undefined index: companyBillingAddress in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>39</b><br />
    <br />
    <b>Notice</b>:  Undefined index: companyShippingAddress in <b>/storage/ssd4/543/15633543/public_html/insertAdmin.php</b> on line <b>40</b><br />
    {"error":200,"message":"Login Failed Try Again","adminUser":[]}

Try using retrofit interceptor. It will show you request and response in the logs and you can see what errors your response has.

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);

OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(logging)
                .build();

Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Common.URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM