Ainda não tem acesso? Estude com a gente! Matricule-se
Ainda não tem acesso? Estude com a gente! Matricule-se
1
resposta

Primeira execução do projeto lança exeção

Acabei de baixar o código do projeto, e ao executar, gera essa exceção:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: br.com.alura.technews, PID: 23326
    java.lang.ExceptionInInitializerError
        at okhttp3.internal.platform.Platform.get(Platform.java:85)
        at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:296)
        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:262)
        at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1054)
        at br.com.alura.technews.retrofit.AppRetrofit$client$2.invoke(AppRetrofit.kt:18)
        at br.com.alura.technews.retrofit.AppRetrofit$client$2.invoke(AppRetrofit.kt:11)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at br.com.alura.technews.retrofit.AppRetrofit.getClient(Unknown Source:7)
        at br.com.alura.technews.retrofit.AppRetrofit.access$getClient$p(AppRetrofit.kt:11)
        at br.com.alura.technews.retrofit.AppRetrofit$retrofit$2.invoke(AppRetrofit.kt:24)
        at br.com.alura.technews.retrofit.AppRetrofit$retrofit$2.invoke(AppRetrofit.kt:11)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at br.com.alura.technews.retrofit.AppRetrofit.getRetrofit(Unknown Source:7)
        at br.com.alura.technews.retrofit.AppRetrofit.access$getRetrofit$p(AppRetrofit.kt:11)
        at br.com.alura.technews.retrofit.AppRetrofit$noticiaService$2.invoke(AppRetrofit.kt:28)
        at br.com.alura.technews.retrofit.AppRetrofit$noticiaService$2.invoke(AppRetrofit.kt:11)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at br.com.alura.technews.retrofit.AppRetrofit.getNoticiaService(Unknown Source:7)
        at br.com.alura.technews.retrofit.webclient.NoticiaWebClient.<init>(NoticiaWebClient.kt:13)
        at br.com.alura.technews.repository.NoticiaRepository.<init>(NoticiaRepository.kt:11)
        at br.com.alura.technews.ui.activity.ListaNoticiasActivity$repository$2.invoke(ListaNoticiasActivity.kt:22)
        at br.com.alura.technews.ui.activity.ListaNoticiasActivity$repository$2.invoke(ListaNoticiasActivity.kt:19)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at br.com.alura.technews.ui.activity.ListaNoticiasActivity.getRepository(Unknown Source:7)
        at br.com.alura.technews.ui.activity.ListaNoticiasActivity.buscaNoticias(ListaNoticiasActivity.kt:59)
        at br.com.alura.technews.ui.activity.ListaNoticiasActivity.onResume(ListaNoticiasActivity.kt:38)
        at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1456)
        at android.app.Activity.performResume(Activity.java:8129)
        at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4434)
        at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4476)
        at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.IllegalStateException: Expected Android API level 21+ but was 30
        at okhttp3.internal.platform.AndroidPlatform.buildIfSupported(AndroidPlatform.java:238)
        at okhttp3.internal.platform.Platform.findPlatform(Platform.java:202)
        at okhttp3.internal.platform.Platform.<clinit>(Platform.java:79)
        at okhttp3.internal.platform.Platform.get(Platform.java:85) 
        at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:296) 
        at okhttp3.OkHttpClient.<init>(OkHttpClient.java:262) 
        at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1054) 
        at br.com.alura.technews.retrofit.AppRetrofit$client$2.invoke(AppRetrofit.kt:18) 
        at br.com.alura.technews.retrofit.AppRetrofit$client$2.invoke(AppRetrofit.kt:11) 
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) 
        at br.com.alura.technews.retrofit.AppRetrofit.getClient(Unknown Source:7) 
        at br.com.alura.technews.retrofit.AppRetrofit.access$getClient$p(AppRetrofit.kt:11) 
        at br.com.alura.technews.retrofit.AppRetrofit$retrofit$2.invoke(AppRetrofit.kt:24) 
        ...
1 resposta

Oi Fabiano, de boa ?

Cara você provavelmente está usando o android studio na versão mais recente, isso implica em algumas coisas não darem certo com as versões que o instrutor usou em video.

Acredito que pro seu problema em especifico, basta atualizar a versão do ok-http para 4.9.0

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software