inflearn logo
강의

Course

Instructor

[LV1] Jetpack Compose - UI Practice

Retrofit - 1

Retrofit 관련 Logcat 화면에 아래 예외가 출력

624

shafeel2

67 asked

0

build.gradle 에 아래를 추가한 후 sync now 하고나서

 

implementation("com.squareup.retrofit2:retrofit:2.9.0")
implementation("com.squareup.retrofit2:converter-gson:2.9.0")

 

아래는 전체코드입니다

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
           val coroutineScope : CoroutineScope = rememberCoroutineScope()
           val retrofitInstance = RetrofitInstance.getInstance().create(MyAPI::class.java)

           Box(
               modifier = Modifier.fillMaxSize(),
               contentAlignment = Alignment.Center,
           ) {
               Button(
                   onClick = {
                       coroutineScope.launch {
                           val response : Response<Post> = retrofitInstance.getPost1()
                           Log.d("MainActivity", response.body().toString())
                       }
                   }
               ) {
                   Text(
                       "Call API"
                   )
               }
           }
        }
    }
}

data class Post(
    val userId : Int,
    val id : Int,
    val title : String,
    val body : String,
)

object RetrofitInstance {
    val BASE_URL = "https://jsonplaceholder.typicode.com/posts/1/"
    val client = Retrofit
        .Builder()
        .baseUrl(BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
    fun getInstance() : Retrofit {
        return client
    }
}

interface MyAPI {
    @GET("posts/1")
    suspend fun getPost1() : Response<Post>
}

 

 위를 실행하니

Logcat 화면에 아래 예외가 출력되고 데이터를 얻어오지 못하는 군요

RemoteConnection failed to initialize: RemoteConnection failed to open pipe

Failed to open QEMU pipe 'qemud:network': Invalid argument

sendWakeUpEvent called on SchedulerClientBroadcastStrategy

GCM_HB_ALARM release without a matched acquire!

 Couldn't load memtrack module

 

수고많으신 강사님

늘 건강하시고 부자되세요

 

android kotlin jetpack

Answer 6

0

shafeel2

알고 보니 코드상에는 문제가 없구요

제가 실수로 안드로이드 스튜디오의

Logcat Pause 버튼을 잘못눌러서

결과물 출력이 않되었군요

 

강사님과 여기 수강하시는 모든 분들

늘 건강하시고 부자되세요 ^^

0

shafeel2

q8.png

Logcat 에는 아무런 출력이 없고

Problems 화면에 위와 같은 출력이 발생합니다

0

bokchi

로그캣에 안나오는 문제는 안드로이드 스튜디오 재시작 / 에뮬레이터 새롭게 만들어서 시도해보시겠어요?

0

shafeel2

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
           val coroutineScope : CoroutineScope = rememberCoroutineScope()
           val retrofitInstance = RetrofitInstance.getInstance().create(MyAPI::class.java)

           Box(
               modifier = Modifier.fillMaxSize(),
               contentAlignment = Alignment.Center,
           ) {
               Button(
                   onClick = {
                       coroutineScope.launch {
                           val response : Response<Post> = retrofitInstance.getPost1()
                           Log.d("MainActivity", response.body().toString())
                       }
                   }
               ) {
                   Text(
                       "Call API"
                   )
               }
           }
        }
    }
}

data class Post(
    val userId : Int,
    val id : Int,
    val title : String,
    val body : String,
)

object RetrofitInstance {
    val BASE_URL = "https://jsonplaceholder.typicode.com/"
    val client = Retrofit
        .Builder()
        .baseUrl(BASE_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
    fun getInstance() : Retrofit {
        return client
    }
}

interface MyAPI {
    @GET("posts/1/")
    suspend fun getPost1() : Response<Post>
}

위와 같이 수정하면

Property 'BASE_URL' could be private

Declaration has type inferred from a platform call, which can lead to unchecked nullability issues. Specify type explicitly as nullable or non-nullable.

Property 'client' could be private

라는 메세지가 problems 창에 출력되고 여전히 Logcat 창에는 아무런 출력이 없군요

0

bokchi

안드로이드 스튜디오를 재시작해도 그런가요?

저는 동일한 코드로 잘 나오는것을 확인했습니다.

image

0

bokchi

안드로이드 스튜디오 재시작 / 에뮬레이터 재실행 후에도 로그가 안나오면 로그창을 스크린샷으로 공유해주세요.

0

bokchi

BASE_URL을 아래와 같이 변경해보세요~

val BASE_URL = "https://jsonplaceholder.typicode.com/"

 

 

 

0

shafeel2

https://drive.google.com/file/d/1dCWrB-EQkFv5FMKG2rWMZclQ4eperCF0/view

구글드라이브 주소입니다

0

bokchi

전체 프로젝트를 압축하셔서 구글 드라이브에 올리신 후 링크를 공유해주시면 살펴볼게요~

6강에 비디오가 이상해요

0

27

2

메인액티비티의 내용이 강의와 다른 것 같습니다.

0

153

2

TextField에서 Cursor의 두께를 조절하는 방법이 있을까요?

0

208

2

TextField에서 테두리 제거하는 방법이 궁금합니다.

0

220

2

강의자료 링크에 접근이 되지 않습니다.

0

268

1

@OptIn(ExperimentalMaterial3Api::class) 질문

0

572

2

Jetpack Compose의 화면구성

1

509

1

프로젝스 생성 시 EmptyComposeActivity를 만드는 건가요?

0

471

1

CoupangEx 4 강에서

0

303

2

HorizontalPagerIndicator 의 pagerState = pageState, 에서 빨간줄이 생깁니다

0

516

2

colorList 에서 빨간줄이 ...

0

230

2

Canvas drawCircle 에서

0

419

5

Canvas drawCircle 에서

0

198

1

이력서앱의 화면이 강사님과는 너무 달라서 어찌 ???

0

911

1

TopAppBar 관련부분에 빨간줄이 ..

0

381

3

Retrofit 관련 url 주소를 적을 때 주의사항입니다

0

302

1

Modifier.weight의 토탈

0

258

1

에뮬에 오류가 뜨네요(WebView)

0

295

2

강의자료실 주소를 알고싶어요

0

435

1

implementation 'androidx.navigation:navigation-compose:2.7.4' 입력시 발생하는 에러 문의합니다.

0

328

1

horizontalArrangement verticalAlignment 관련질문입니다

0

283

3

혹시 Lv2 강의는 언제쯤 올라오는 알수잇을까요?

0

314

2

강사님 닉네임에 생각나는 것이 있어용 ^^

0

239

1

웹뷰 화면 깨짐 현상에 대해 질문드립니다!

0

2014

2