Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何修复我的应用程序中的IllegalArgumentException改装_Android_Kotlin_Retrofit - Fatal编程技术网

Android 如何修复我的应用程序中的IllegalArgumentException改装

Android 如何修复我的应用程序中的IllegalArgumentException改装,android,kotlin,retrofit,Android,Kotlin,Retrofit,你好,我正在努力研究改装,我遇到了这个问题 工艺:kotlincodes.com.WithKotlin,PID:14957 java.lang.RuntimeException:无法启动活动组件信息{kotlincodes.com.RefundationWithKotlin/kotlincodes.com.RefundationWithKotlin.activity.MainActivity}:java.lang.IllegalArgumentException:@字段参数只能与表单编码一起使用

你好,我正在努力研究改装,我遇到了这个问题

工艺:kotlincodes.com.WithKotlin,PID:14957 java.lang.RuntimeException:无法启动活动组件信息{kotlincodes.com.RefundationWithKotlin/kotlincodes.com.RefundationWithKotlin.activity.MainActivity}:java.lang.IllegalArgumentException:@字段参数只能与表单编码一起使用。(参数#1) 对于方法ApiInterface.getHistory 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)上 位于android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 位于android.app.ActivityThread.-wrap11(ActivityThread.java) 在android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)上 位于android.os.Handler.dispatchMessage(Handler.java:102) 位于android.os.Looper.loop(Looper.java:148) 位于android.app.ActivityThread.main(ActivityThread.java:5417) 位于java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run上(ZygoteInit.java:726) 位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 原因:java.lang.IllegalArgumentException:@字段参数只能与表单编码一起使用。(参数#1) 对于方法ApiInterface.getHistory 在2.ServiceMethod$Builder.methodError处(ServiceMethod.java:752) 在2.ServiceMethod$Builder.methodError处(ServiceMethod.java:743) 在2.ServiceMethod$Builder.parameterError处(ServiceMethod.java:761) 在2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.java:533)处 在2.ServiceMethod$Builder.parseParameter处(ServiceMethod.java:336) 在2.ServiceMethod$Builder.build处(ServiceMethod.java:204) 在Refundation2.Refundation.loadServiceMethod(Refundation.java:170)中 在reformation2.reformation$1.invoke(reformation.java:147) 位于java.lang.reflect.Proxy.invoke(Proxy.java:393) 位于$Proxy0.getHistory(未知源) 在kotlincodes.com.reformationWithKotlin.activity.MainActivity.getDat1a(MainActivity.kt:41)//这里是MainActivity中的错误 在kotlincodes.com.infractwithkotlin.activity.MainActivity.onCreate(MainActivity.kt:36) 位于android.app.Activity.performCreate(Activity.java:6237) 位于android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)上

这是我的密码

客户:

object ApiClient {

var BASE_URL:String="http://192.168.1.6/Matloob/"

val getClient: ApiInterface
    get() {

        val gson = GsonBuilder()
                .setLenient()
                .create()

        val interceptor = HttpLoggingInterceptor()
        interceptor.level = HttpLoggingInterceptor.Level.BODY
        val client = OkHttpClient.Builder().addInterceptor(interceptor).build()

        val retrofit = Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build()

        return retrofit.create(ApiInterface::class.java)

    }
}
API接口:-

interface ApiInterface {

@GET("getHistory.php")
fun getHistory(
    @Field("toemail") toemail:String,
    @Field("toname") toname:String
): Call<List<DataModel>>

}
该功能是主要活动:-

private fun getDat1a() {
    val call: Call<List<DataModel>> = ApiClient.getClient.getHistory("khairo.humsi@mail.ru", "khairo humsi")
    call.enqueue(object : Callback<List<DataModel>> {

        override fun onResponse(call: Call<List<DataModel>>?, response: Response<List<DataModel>>?) {
            pd.dismiss()
            list.addAll(response!!.body()!!)
            recyclerView.adapter?.notifyDataSetChanged()
        }

        override fun onFailure(call: Call<List<DataModel>>?, t: Throwable?) {
            pd.dismiss()
        }

    })
}
private fun getDat1a(){
val call:call=ApiClient.getClient.getHistory(“khairo。humsi@mail.ru“,“khairo humsi”)
排队(对象:Callback{
覆盖fun onResponse(调用:调用?,响应:响应?){
pd.解雇()
list.addAll(response!!.body()!!)
recyclerView.adapter?.notifyDataSetChanged()
}
覆盖失效时的乐趣(调用:调用?、t:可丢弃?){
pd.解雇()
}
})
}
最后这是我的适配器

class DataAdpter(private var list: List<DataModel>, private val context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onBindViewHolder(p0: RecyclerView.ViewHolder, p1: Int) {
    (p0 as ItemView).bind(list[p1].name, list[p1].email, list[p1].number, list[p1].data, list[p1].time, list[p1].image, list[p1].lat, list[p1].lng, list[p1].rate, list[p1].ratecount)

}

override fun getItemCount(): Int {
   return list.size
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    return ItemView(LayoutInflater.from(context).inflate(R.layout.row_history, parent, false))
}


class ItemView(itemVeiw: View) : RecyclerView.ViewHolder(itemVeiw) {

    fun bind(name: String, email: String, number: String
             , data: String, time: String, image: String, lat: Double, lng: Double, rate: Double, ratecount: Int) {

        itemView.name.text= name
        itemView.historyRate.isEnabled= false
        itemView.emailtext.text= email
        itemView.phonetext.text= number
        itemView.datatext.text= data
        itemView.timetext.text= time
        Picasso.with(itemView.context).load(image).into(itemView.ivRowCategoryImage)

        itemView.lat.text= lat.toString()
        itemView.lng.text= lng.toString()

        itemView.historyRate.rating = ((rate/ratecount).toFloat())


    }
}

}
classdataadpter(private-var-list:list,private-val-context:context):RecyclerView.Adapter(){
覆盖BindViewHolder(p0:RecyclerView.ViewHolder,p1:Int){
(p0作为ItemView)。绑定(列表[p1]。名称,列表[p1]。电子邮件,列表[p1]。编号,列表[p1]。数据,列表[p1]。时间,列表[p1]。图像,列表[p1]。lat,列表[p1]。lng,列表[p1]。费率,列表[p1]。费率计数)
}
重写getItemCount():Int{
返回列表。大小
}
override fun onCreateViewHolder(父级:ViewGroup,viewType:Int):RecyclerView.ViewHolder{
return ItemView(LayoutInflater.from(context).充气(R.layout.row\u history,parent,false))
}
类ItemView(ItemView:View):RecyclerView.ViewHolder(ItemView){
趣味绑定(名称:String,电子邮件:String,编号:String)
,数据:字符串,时间:字符串,图像:字符串,纬度:双精度,液化天然气:双精度,速率:双精度,速率计数:整数){
itemView.name.text=名称
itemView.historyRate.isEnabled=false
itemView.emailtext.text=电子邮件
itemView.phonetext.text=number
itemView.datatext.text=数据
itemView.timetext.text=时间
毕加索.with(itemView.context).load(image).into(itemView.ivRowCategoryImage)
itemView.lat.text=lat.toString()
itemView.lng.text=lng.toString()
itemView.historyRate.rating=((rate/ratecount.toFloat())
}
}
}
接口API接口{
@获取(“getHistory.php”)
有趣的历史(
@查询(“toemail”)toemail:String,
@查询(“toname”)toname:String
):呼叫
}
接口API接口{
@获取(“getHistory.php”)
有趣的历史(
@查询(“toemail”)toemail:String,
@查询(“toname”)toname:String
):呼叫
}

@Field()
用于
@POST
@FormUrlEncoded
。您应该改用
@Query()

@Field()
用于带有
@FormUrlEncoded
@POST
。您应该改用
@Query()

抱歉,kotlincodes.com.RefundationWithKotlin.activity.MainActivity.getDat1a(MainActivity.kt:41)上的kotlincodes.com.RefundationWithKotlin.activity.MainActivity.onCreate(MainActivity.kt:36)上出现相同错误它在github/retrofirUsed@query字段实例中出现了黄色检查问题。很抱歉,kotlincodes.com.RefundWithKotlin.activity.MainActivity.getDat1a(MainActivity.kt:41)上的kotlincodes.com.RefundWithKotlin.activity.MainActivity.onCreate(MainActivity.kt:36)上出现了相同的错误它位于字段的github/retrofirUsed@query实例中的up-in-yellowCheck问题中
class DataAdpter(private var list: List<DataModel>, private val context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onBindViewHolder(p0: RecyclerView.ViewHolder, p1: Int) {
    (p0 as ItemView).bind(list[p1].name, list[p1].email, list[p1].number, list[p1].data, list[p1].time, list[p1].image, list[p1].lat, list[p1].lng, list[p1].rate, list[p1].ratecount)

}

override fun getItemCount(): Int {
   return list.size
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
    return ItemView(LayoutInflater.from(context).inflate(R.layout.row_history, parent, false))
}


class ItemView(itemVeiw: View) : RecyclerView.ViewHolder(itemVeiw) {

    fun bind(name: String, email: String, number: String
             , data: String, time: String, image: String, lat: Double, lng: Double, rate: Double, ratecount: Int) {

        itemView.name.text= name
        itemView.historyRate.isEnabled= false
        itemView.emailtext.text= email
        itemView.phonetext.text= number
        itemView.datatext.text= data
        itemView.timetext.text= time
        Picasso.with(itemView.context).load(image).into(itemView.ivRowCategoryImage)

        itemView.lat.text= lat.toString()
        itemView.lng.text= lng.toString()

        itemView.historyRate.rating = ((rate/ratecount).toFloat())


    }
}

}
interface ApiInterface {

@GET("getHistory.php")
fun getHistory(
    @query("toemail") toemail:String,
    @query("toname") toname:String
): Call<List<DataModel>>

}