没有参数错误改造请求正文
我正在使用改进发送json对象体到服务器时遇到问题。 以下是错误。
无法调用公共com.nitesh.brill.saleslines._User_Classes.User_PojoClass.UpdatePreviousDetails()没有参数
代码片段
// Api端点
@Headers("Content-Type: application/json") @POST("UpdatePreviousDetails/{Id}") fun updatePreviousDetails(@Path("Id") Id: Int, @Body updateDetails :UpdatePreviousDetails): Call<UpdatePreviousDetails>
// pojo类
package com.nitesh.brill.saleslines._User_Classes.User_PojoClass import java.util.* /** * Created by Nitesh Android on 16-08-2017. */ class UpdatePreviousDetails( var CompanyName: String? = null!!, var Designation: String? = null!!, var DateOfJoin: Date? = null!!, var DateOfLeaving: Date? = null!!, var SectorPreviouslyWorked: String? = null!!, var Id: Int? = null!! ) { }
//发送数据
val details = UpdatePreviousDetails("rr", "asm", date, date, "Pharmaceuticals",3) val call = apiEndpointInterface!!.updatePreviousDetails(5, details) call.enqueue(object :Callback<UpdatePreviousDetails> { override fun onResponse(call: Call<UpdatePreviousDetails>?, response: Response<UpdatePreviousDetails>?) { objUsefullData.showSnackBar("success") UsefullData.Log("============="+response!!.body().toString()) } override fun onFailure(call: Call<UpdatePreviousDetails>?, t: Throwable?) { objUsefullData.showSnackBar("fail") UsefullData.Log("============="+t) } })
我正在使用kotlin语言
你的UpdatePreviousDetails
类必须有一个没有参数的构造函数来启用Gson(在Retrofit中)将你的对象转换成JSON。
编辑
class UpdatePreviousDetails() { var CompanyName: String? = null var Designation: String? = null var DateOfJoin: Date? = null var DateOfLeaving: Date? = null var SectorPreviouslyWorked: String? = null var Id: Int? = null constructor( CompanyName: String?, Designation: String?, DateOfJoin: Date?, DateOfLeaving: Date?, SectorPreviouslyWorked: String?, Id: Int? ) : this() { this.CompanyName = CompanyName this.Designation = Designation this.DateOfJoin = DateOfJoin this.DateOfLeaving = DateOfLeaving this.SectorPreviouslyWorked = SectorPreviouslyWorked this.Id = Id } }
- 我在android项目中使用这个库,但使用https://github.com/igalata/Bubble-Picker/错误
- WeakReference不在Kotlin工作
- 安装Kotlin Android项目失败INSTALL_FAILED_DEXOPT
- 如何在kotlin中“静态”访问类的成员?
- 匕首和登录凭证
- java.lang.NoClassDefFoundError:com.example.api.retrofit.AuthenticationInterceptor $ intercept $ 1
- Kotlin Android Project无法同步Gradle项目
- 无法上传Android中的文件,并且没有错误的详细信息
- Android Studio 3无法建立kotlin片段