【问题标题】:No args error retrofit request body没有 args 错误改造请求正文
【发布时间】:2018-01-24 10:57:26
【问题描述】:

我在使用改造向服务器发送 json 对象主体时遇到问题。以下是错误。

调用公共失败 com.nitesh.brill.saleslines._User_Classes.User_PojoClass.UpdatePreviousDetails() 没有参数

代码sn-p

// 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 语言

【问题讨论】:

    标签: android kotlin retrofit


    【解决方案1】:

    您的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
        }
    }
    

    【讨论】:

    • 我该怎么做,请给任何参考
    • @NIteshKumar 我刚刚编辑了我的答案,请查看。
    • @NIteshKumar NellPointerException 出现在哪里? null 是什么?
    猜你喜欢
    • 2018-06-05
    • 2020-02-25
    • 1970-01-01
    • 2015-11-25
    • 2016-06-16
    • 2019-04-12
    • 2018-07-24
    • 2018-04-04
    • 2016-11-17
    相关资源
    最近更新 更多