I am using Android Fast Networking Library When I am trying to get Images from Server I am getting the error even I have successfully Uploaded all images to server error in getting back them 6 images
private fun callProfileApi() {
binding.progressBar.visibility=View.VISIBLE
AndroidNetworking.post(Constant.BASE_URL + "app.php?api=userprofile")
.addUrlEncodeFormBodyParameter("userid", usetId)
.setTag("userprofile")
.setPriority(Priority.MEDIUM)
.build()
.getAsString(object : StringRequestListener {
override fun onResponse(response: String) {
AppLogger.e("MoodMatch response","====="+response)
Log.d("@@", response)
var gson: Gson = Gson()
var userProfileModel = gson.fromJson(response, UserProfileModel::class.java)
if (!(userProfileModel.error ?: true)){
if(userProfileModel.data!=null){
updateUI(userProfileModel)
}else{
AppLogger.toast("Something went wrong")
}
}else{
AppLogger.toast(userProfileModel.message)
}
binding.progressBar.visibility=View.GONE
}
override fun onError(error: ANError) {
// handle error
AppLogger.toast(error.localizedMessage)
Log.e("@@MoodMatc honError", "=======" + error.localizedMessage)
binding.progressBar.visibility=View.GONE
}
})
}
I am Getting Error in this line like this :
var userProfileModel = gson.fromJson(response, UserProfileModel::class.java)
Inside Log, I am getting like this
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 226 path $.data.images[0]
Here is my Model Class :
class UserProfileModel {
@Expose
@SerializedName("data")
var data: Data? = null
@SerializedName("error")
var error: Boolean? = null
@SerializedName("message")
var message: String? = null
}
and here is data class :
class Data {
@SerializedName("about")
var about: String? = null
@SerializedName("account_locked")
var accountLocked: String? = null
@SerializedName("address")
var address: String? = null
@SerializedName("city")
var city: String? = null
@SerializedName("company_policy")
var companyPolicy: String? = null
@SerializedName("created_at")
var createdAt: String? = null
@SerializedName("distance_in")
var distanceIn: String? = null
@SerializedName("dob")
var dob: String? = null
@SerializedName("education")
var education: String? = null
@SerializedName("email")
var email: String? = null
@SerializedName("age")
var age: String? = null
@SerializedName("email_otp")
var emailOtp: String? = null
@SerializedName("fb_link")
var fbLink: String? = null
@SerializedName("first_name")
var firstName: String? = null
@SerializedName("first_time_login")
var firstTimeLogin: String? = null
@SerializedName("gender")
var gender: String? = null
@SerializedName("hobby")
var hobby: String? = null
@SerializedName("id")
var id: String? = null
@SerializedName("image")
var image: String? = null
@SerializedName("insta_link")
var instaLink: String? = null
@SerializedName("intersted_in")
var interstedIn: String? = null
@SerializedName("last_name")
var lastName: String? = null
@SerializedName("login_attempt")
var loginAttempt: String? = null
@SerializedName("membership_type")
var membershipType: String? = null
@SerializedName("membershipid")
var membershipid: String? = null
@SerializedName("mood_id")
var moodId: String? = null
@SerializedName("notification_type")
var notificationType: String? = null
@SerializedName("password")
var password: String? = null
@SerializedName("phone_number")
var phoneNumber: String? = null
@SerializedName("referral_code")
var referralCode: String? = null
@SerializedName("role")
var role: String? = null
@SerializedName("social_id")
var socialId: String? = null
@SerializedName("social_type")
var socialType: String? = null
@SerializedName("status")
var status: String? = null
@SerializedName("term_conditions")
var termConditions: String? = null
@SerializedName("updated_at")
var updatedAt: String? = null
@SerializedName("username")
var username: String? = null
@SerializedName("which_age_people")
var whichAgePeople: String? = null
@SerializedName("images")
var mImages: List<Image>? = null
}
Api response :
{
"error": false,
"data": {
"id": "149",
"username": "kamal kumar",
"email": "[email protected]",
"phone_number": "9057217361",
"address": "B-209, Rajendra Marg, Bapu Nagar, Jaipur, Rajasthan 302015, India",
"city": "Jaipur",
"images": [
"http://moodsmatch.com/admin/uploads/20191209_151815.jpg",
"http://moodsmatch.com/admin/uploads/29261010_1348876641925767_1868739767978426368_n.jpg",
"http://moodsmatch.com/admin/uploads/20191209_112909.jpg",
"http://moodsmatch.com/admin/uploads/IMG_2ljalw.jpg",
"http://moodsmatch.com/admin/uploads/20191209_150617.jpg",
"http://moodsmatch.com/admin/uploads/FB_IMG_1575778091267.jpg"
],
"state": "Rajasthan",
"country": "India",
"referral_code": "Fnt4oe7C",
"referral_points": "0",
"membership_type": "Free",
"intersted_in": "",
"distance_in": "",
"defaultDistance": "5M",
"image": "http://www.moodsmatch.com/admin/../uploads/",
"gender": "Male",
"age": 0,
"dob": "12/02/2019",
"education": "he is a very good person ",
"hobby": "",
"about": "he is a very good person "
},
"message": "Record match"
}
Please suggest me how to resolve this Thank you in Advance, I would appreciate every answer
Use the below declaration for images array.