Я пытаюсь получить здесь данные от artic.edu api, и я использую здесь с GSON Converter, и это не работает. Я попробовал это без @path и сделал это в жестком кодировании, и таким образом это сработало. Каждый раз, когда я пробую его с приложением @Path закрывает и выводит ошибку.
My MainActivity Code: < /p>
import ***
class MainActivity : ComponentActivity() {
private var articData = mutableStateOf(Artic())
private var id = mutableIntStateOf(1)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Surface(
modifier = Modifier
.fillMaxSize()
.clickable {
id.intValue=id.intValue+1
sendResponse(4)
},
color = MaterialTheme.colorScheme.background
) {
sendResponse(4)
MyUi(articData = articData)
}
}
}
@OptIn(DelicateCoroutinesApi::class)
fun sendResponse(idInputed:Int) {
GlobalScope.launch(Dispatchers.IO) {
val response = try {
RetrofitInstance.api.GetDataArr(idInputed)
} catch (e: HttpException) {
Toast.makeText(applicationContext, "http error: ${e.message}", Toast.LENGTH_SHORT)
.show()
return@launch
} catch (e: IOException) {
Toast.makeText(applicationContext, "app error: ${e.message}", Toast.LENGTH_SHORT)
.show()
return@launch
}
if (response.isSuccessful) {
withContext(Dispatchers.Main) {
articData.value = response.body()!!
}
}
}
}
}
@Composable
fun MyUi(articData: MutableState, modifier: Modifier = Modifier) {
Column(modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center
) {
Text(
text = articData.value.data[0].title, fontSize = 26.sp,
lineHeight = 20.sp,
textAlign = TextAlign.Center
)
if(articData.value.data[0].short_description!=null){
Text(
text = articData.value.data[0].short_description!!, fontSize = 16.sp,
lineHeight = 20.sp,
textAlign = TextAlign.Center
)
}
Text(
text = articData.value.data[0].artist_title, fontSize = 16.sp,
lineHeight = 20.sp,
textAlign = TextAlign.Center
)
Text(
text = articData.value.data[0].date_display, fontSize = 16.sp,
lineHeight = 20.sp,
textAlign = TextAlign.Center
)
}
}
< /code>
Здесь это экземпляр Monhofit: < /p>
object RetrofitInstance {
val api : ApiInterface by lazy{
Retrofit.Builder()
.baseUrl("https://api.artic.edu")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApiInterface::class.java)
}
}
< /code>
Вот Apiinterface: < /p>
interface ApiInterface {
@GET("/api/v1/artworks?exclude=data&limit=1&fields=title%2Cimage_id%2Cdate_display%2Cartist_title%2Cshort_description&page={id}")
suspend fun GetDataArr(@Path(value = "id") id : Int): Response
}
< /code>
Вот logcat of: < /p>
Process: com.rerebo.library, PID: 6827
java.lang.IllegalArgumentException: URL query string "exclude=data&limit=1&fields=title%2Cimage_id%2Cdate_display%2Cartist_title%2Cshort_description&page={id}" must not have replace block. For dynamic query parameters use @Query.
for method ApiInterface.GetDataArr
at retrofit2.Utils.methodError(Utils.java:56)
at retrofit2.Utils.methodError(Utils.java:44)
at retrofit2.RequestFactory$Builder.parseHttpMethodAndPath(RequestFactory.java:292)
at retrofit2.RequestFactory$Builder.parseMethodAnnotation(RequestFactory.java:236)
at retrofit2.RequestFactory$Builder.build(RequestFactory.java:188)
at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:235)
at retrofit2.Retrofit$1.invoke(Retrofit.java:177)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy2.GetDataArr(Unknown Source)
at com.rerebo.library.MainActivity$sendResponse$1.invokeSuspend(MainActivity.kt:69)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@bfce7dc, Dispatchers.IO]
2025-07-03 11:54:33.873 6827-6845 HostConnection com.rerebo.library D HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_vulkan_batched_descriptor_set_update ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_1
2025-07-03 11:54:33.954 6827-6827 Choreographer com.rerebo.library I Skipped 48 frames! The application may be doing too much work on its main thread.
2025-07-03 11:54:34.005 6827-6840 OpenGLRenderer com.rerebo.library I Davey! duration=1187ms; Flags=1, FrameTimelineVsyncId=7009, IntendedVsync=2637648596360, Vsync=2637881929684, InputEventId=0, HandleInputStart=2637891850000, AnimationStart=2637891886600, PerformTraversalsStart=2637892185300, DrawStart=2638757287300, FrameDeadline=2637665263026, FrameInterval=2637891816000, FrameStartTime=16666666, SyncQueued=2638768785000, SyncStart=2638782650300, IssueDrawCommandsStart=2638797462800, SwapBuffers=2638808262200, FrameCompleted=2638850352600, DequeueBufferDuration=58500, QueueBufferDuration=3088300, GpuCompleted=2638850352600, SwapBuffersCompleted=2638826929500, DisplayPresentTime=0,
2025-07-03 11:54:34.008 6827-6848 Process com.rerebo.library I Sending signal. PID: 6827 SIG: 9
---------------------------- PROCESS ENDED (6827) for package com.rerebo.library ----------------------------
Подробнее здесь: https://stackoverflow.com/questions/796 ... oesnt-work
Я пытаюсь использовать @path в модернизации Android Studio, но это не работает ⇐ Android
Форум для тех, кто программирует под Android
1751530797
Anonymous
Я пытаюсь получить здесь данные от artic.edu api, и я использую здесь с GSON Converter, и это не работает. Я попробовал это без @path и сделал это в жестком кодировании, и таким образом это сработало. Каждый раз, когда я пробую его с приложением @Path закрывает и выводит ошибку.
My MainActivity Code: < /p>
import ***
class MainActivity : ComponentActivity() {
private var articData = mutableStateOf(Artic())
private var id = mutableIntStateOf(1)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Surface(
modifier = Modifier
.fillMaxSize()
.clickable {
id.intValue=id.intValue+1
sendResponse(4)
},
color = MaterialTheme.colorScheme.background
) {
sendResponse(4)
MyUi(articData = articData)
}
}
}
@OptIn(DelicateCoroutinesApi::class)
fun sendResponse(idInputed:Int) {
GlobalScope.launch(Dispatchers.IO) {
val response = try {
RetrofitInstance.api.GetDataArr(idInputed)
} catch (e: HttpException) {
Toast.makeText(applicationContext, "http error: ${e.message}", Toast.LENGTH_SHORT)
.show()
return@launch
} catch (e: IOException) {
Toast.makeText(applicationContext, "app error: ${e.message}", Toast.LENGTH_SHORT)
.show()
return@launch
}
if (response.isSuccessful) {
withContext(Dispatchers.Main) {
articData.value = response.body()!!
}
}
}
}
}
@Composable
fun MyUi(articData: MutableState, modifier: Modifier = Modifier) {
Column(modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center
) {
Text(
text = articData.value.data[0].title, fontSize = 26.sp,
lineHeight = 20.sp,
textAlign = TextAlign.Center
)
if(articData.value.data[0].short_description!=null){
Text(
text = articData.value.data[0].short_description!!, fontSize = 16.sp,
lineHeight = 20.sp,
textAlign = TextAlign.Center
)
}
Text(
text = articData.value.data[0].artist_title, fontSize = 16.sp,
lineHeight = 20.sp,
textAlign = TextAlign.Center
)
Text(
text = articData.value.data[0].date_display, fontSize = 16.sp,
lineHeight = 20.sp,
textAlign = TextAlign.Center
)
}
}
< /code>
Здесь это экземпляр Monhofit: < /p>
object RetrofitInstance {
val api : ApiInterface by lazy{
Retrofit.Builder()
.baseUrl("https://api.artic.edu")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApiInterface::class.java)
}
}
< /code>
Вот Apiinterface: < /p>
interface ApiInterface {
@GET("/api/v1/artworks?exclude=data&limit=1&fields=title%2Cimage_id%2Cdate_display%2Cartist_title%2Cshort_description&page={id}")
suspend fun GetDataArr(@Path(value = "id") id : Int): Response
}
< /code>
Вот logcat of: < /p>
Process: com.rerebo.library, PID: 6827
java.lang.IllegalArgumentException: URL query string "exclude=data&limit=1&fields=title%2Cimage_id%2Cdate_display%2Cartist_title%2Cshort_description&page={id}" must not have replace block. For dynamic query parameters use @Query.
for method ApiInterface.GetDataArr
at retrofit2.Utils.methodError(Utils.java:56)
at retrofit2.Utils.methodError(Utils.java:44)
at retrofit2.RequestFactory$Builder.parseHttpMethodAndPath(RequestFactory.java:292)
at retrofit2.RequestFactory$Builder.parseMethodAnnotation(RequestFactory.java:236)
at retrofit2.RequestFactory$Builder.build(RequestFactory.java:188)
at retrofit2.RequestFactory.parseAnnotations(RequestFactory.java:67)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:26)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:235)
at retrofit2.Retrofit$1.invoke(Retrofit.java:177)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy2.GetDataArr(Unknown Source)
at com.rerebo.library.MainActivity$sendResponse$1.invokeSuspend(MainActivity.kt:69)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@bfce7dc, Dispatchers.IO]
2025-07-03 11:54:33.873 6827-6845 HostConnection com.rerebo.library D HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_vulkan_batched_descriptor_set_update ANDROID_EMU_sync_buffer_data ANDROID_EMU_vulkan_async_qsri ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_1
2025-07-03 11:54:33.954 6827-6827 Choreographer com.rerebo.library I Skipped 48 frames! The application may be doing too much work on its main thread.
2025-07-03 11:54:34.005 6827-6840 OpenGLRenderer com.rerebo.library I Davey! duration=1187ms; Flags=1, FrameTimelineVsyncId=7009, IntendedVsync=2637648596360, Vsync=2637881929684, InputEventId=0, HandleInputStart=2637891850000, AnimationStart=2637891886600, PerformTraversalsStart=2637892185300, DrawStart=2638757287300, FrameDeadline=2637665263026, FrameInterval=2637891816000, FrameStartTime=16666666, SyncQueued=2638768785000, SyncStart=2638782650300, IssueDrawCommandsStart=2638797462800, SwapBuffers=2638808262200, FrameCompleted=2638850352600, DequeueBufferDuration=58500, QueueBufferDuration=3088300, GpuCompleted=2638850352600, SwapBuffersCompleted=2638826929500, DisplayPresentTime=0,
2025-07-03 11:54:34.008 6827-6848 Process com.rerebo.library I Sending signal. PID: 6827 SIG: 9
---------------------------- PROCESS ENDED (6827) for package com.rerebo.library ----------------------------
Подробнее здесь: [url]https://stackoverflow.com/questions/79688427/i-am-trying-to-use-path-in-android-studio-retrofit-but-it-doesnt-work[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия