我制作了一个应用程序,它使用改造来访问我的本地主机服务器并向用户发布数据。应用程序中的代码有效,因为我在虚拟设备和手机上通过网站进行了尝试 https://jsonplaceholder.typicode.com/
php 可以工作,因为我用邮递员尝试过,它可以工作
但是当我尝试连接时,我在 logcat 中收到此错误
SDAgentPac...teReceiver system_server E Not going to handle 'com.example.retrofitviewsphpsql'!
2023-12-25 14:39:19.521 4227-4306 ResourcesManager system_server E failed to add asset path /data/app/com.example.retrofitviewsphpsql-MhzxSZfwEKBGUjg11dD7tA==/base.apk
2023-12-25 14:39:20.900 14882-14882 AppCompatDelegate com.example.retrofitviewsphpsql D Checking for metadata for AppLocalesMetadataHolderService : Service not found
2023-12-25 14:39:21.949 4227-4227 SDAgentPac...teReceiver system_server E Not going to handle 'com.example.retrofitviewsphpsql'!
2023-12-25 14:39:22.100 14882-14969 OpenGLRenderer com.example.retrofitviewsphpsql D HWUI GL Pipeline
2023-12-25 14:39:22.133 14882-14951 AndroidRuntime com.example.retrofitviewsphpsql E FATAL EXCEPTION: DefaultDispatcher-worker-1
Process: com.example.retrofitviewsphpsql, PID: 14882
java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but no colon was found
at okhttp3.HttpUrl$Builder.parse(HttpUrl.java:1332)
at okhttp3.HttpUrl.get(HttpUrl.java:917)
at retrofit2.Retrofit$Builder.baseUrl(Retrofit.java:506)
at com.example.retrofitviewsphpsql.RetrofitInstance$api$2.invoke(RetrofitInstance.kt:11)
at com.example.retrofitviewsphpsql.RetrofitInstance$api$2.invoke(RetrofitInstance.kt:9)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
at com.example.retrofitviewsphpsql.RetrofitInstance.getApi(RetrofitInstance.kt:9)
at com.example.retrofitviewsphpsql.MainActivity$postRequest$1.invokeSuspend(MainActivity.kt:102)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
2023-12-25 14:39:22.167 14882-14896 zygote com.example.retrofitviewsphpsql I Background concurrent copying GC freed 4750(1005KB) AllocSpace objects, 0(0B) LOS objects, 49% free, 1654KB/3MB, paused 1.265ms total 132.302ms
2023-12-25 14:39:22.172 14882-14882 InputTransport com.example.retrofitviewsphpsql D Input channel constructed: fd=56
我环顾四周,致命异常似乎是协程出了问题,但“不打算处理‘应用程序名称’是新的。
我已经检查了我尝试访问的地址是
const val BASE = "IP/MyApplication/v1/registerUser.php"
和 POST 功能
@POST("/posts")
suspend fun createPost(
@Body user: User
):Response<User>
这些网址有问题吗?
url路径错误 它需要的底座需要像这样
"http://ip/appname/v1/"
和@POST(“/namefile.php”)