kotlin 第1行第1列路径$处的输入结束-其他解决方案无法解决

qyyhg6bp  于 2023-06-06  发布在  Kotlin
关注(0)|答案(1)|浏览(257)

新来的API。
我有一个工作的API。我的Get和Post工作了。现在只有我的get工作,我的帖子使我的应用程序崩溃后,每一个职位。
最初,当它确实工作时,我得到了500的错误代码。服务器端。从那时起,我们已经在服务器上工作,并修复了一些其他问题,但是现在-我用get获取我的数据,没有问题发生。当我发布得到以下内容:

I/System.out: --> POST http://intranet.localnet:777/?q=8&ID=Tab04&p1=0&p2=0000210965
    I/System.out: Content-Length: 0
    I/System.out: --> END POST (0-byte body)
    I/System.out: <-- 200 OK http://intranet.localnet:777/?q=8&ID=Tab04&p1=0&p2=0000210965 
    (745ms)
    I/System.out: Connection: close
    I/System.out: Content-Type: text/html
    I/System.out: Server: Indy/9.00.10
    I/System.out: <-- END HTTP (0-byte body)
    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.dispatch.tripsheet, PID: 21559
        java.io.EOFException: End of input at line 1 column 1 path $

我不知道其余的错误是否是必要的“at. com. google...”-所以我把它留了下来。
如图所示,我确实成功到达了服务器,并且它确实更新了数据库。但我的应用程序在每个示例上都崩溃了。
下面是我的API代码:

object RetrofitInstance {
        
            val nullOnEmptyConverterFactory = object : Converter.Factory() {
                fun converterFactory() = this
                override fun responseBodyConverter(type: Type, annotations: Array<out 
        Annotation>, retrofit: Retrofit) = object : Converter<ResponseBody, Any?> {
                    val nextResponseBodyConverter = retrofit.nextResponseBodyConverter<Any?> 
       (converterFactory(), type, annotations)
                    override fun convert(value: ResponseBody) = if (value.contentLength() != 0L) 
        nextResponseBodyConverter.convert(value) else null
                }
            }
            
            val loggingInterceptor: HttpLoggingInterceptor = HttpLoggingInterceptor { message -> 
        // Log the request URL
                println("$message")
            }.setLevel(Level.BODY)
        
            private val httpClient = OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor)
                .build()
        
            private val retrofit by lazy {
                Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .client(httpClient)
                    .addConverterFactory(nullOnEmptyConverterFactory)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build()
            }
        
            val api: API by lazy {
                retrofit.create(API::class.java)
            }
        
        }

下面是我的MainViewModelFactory代码:

class MainViewModelFactory(private val repository: Repository):  ViewModelProvider.Factory {
            override fun <T : ViewModel?> create(modelClass: Class<T>): T {
                return MainViewModel(repository) as T
            } }

下面是我的MainViewModel代码:

fun pushClear(uniqueId: String, DELIVERED: Int = 0, delno: String) {
            viewModelScope.launch {
                val call = repository.pushClear(uniqueId, DELIVERED, delno)
                call.enqueue(object : Callback<Unit> {
                    override fun onResponse(call: Call<Unit>, response: Response<Unit>){
                    }
                    override fun onFailure(call: Call<Unit>, t: Throwable) {
                    }
    
                })
        //            val response = repository.pushClear(uniqueId, DELIVERED, delno)
        //            myPost6.value = response
            }
        }

下面是我的代码库:

suspend fun pushClear(uniqueId: String, DELIVERED: Int = 0, delno: String): Call<Unit> {
            return RetrofitInstance.api.pushClear(uniqueId, DELIVERED, delno)
        }

下面是我的文章代码:

@POST("/?q=8")
        suspend fun pushClear(
            @Query("ID") uniqueId: String,
            @Query("p1") DELIVERED: Int = 0,
            @Query("p2") delno: String
        ): Call<Unit>

下面是我调用POST时的代码:

val repository = Repository()
                val viewModelFactory = MainViewModelFactory(repository)
                viewModel = ViewModelProvider(this, 
                viewModelFactory).get(MainViewModel::class.java)
                viewModel.pushClear(uniqueId,0, DELNO)

我已经看到了很多类似的问题与End of input at line 1 column 1 path $.我已经尝试了所有的解决方案,但没有成功,这就是为什么我问我的问题。我尝试了以下方法:使用void -Retrofit 2 End of input at line 1 column 1 path $添加NullConverterFactory -How to solve E/error: End of input at line 1 column 1 path $ in android studio使用call -Retrofit 2 : End of input at line 1 column 1 path $
我可以将服务器更改为响应{"OK": "Cupcake"}。但是,这需要服务器反馈。可以规避吗?

3qpi33ja

3qpi33ja1#

只是浏览了一下你的问题,我认为这个一般性错误End of input at...是因为你的代码在成功的POST后期望从服务器返回某种类型的(序列化对象)。反序列化器找不到任何数据来生成对象,因为数据流是空的,你可以在这里看到最后一行:

I/System.out: <-- 200 OK http://intranet.localnet:777/?q=8&ID=Tab04&p1=0&p2=0000210965 
    (745ms)
    I/System.out: Connection: close
    I/System.out: Content-Type: text/html
    I/System.out: Server: Indy/9.00.10
    I/System.out: <-- END HTTP (0-byte body)

0-byte body
因此,您的代码应该更改为删除将返回对象的预期(或更改服务器以返回某些内容)。

相关问题