Я пытаюсь получить json из API, используя okhttp, и когда я пытаюсь это сделать, приложение разрушается, и я получаю исключение времени выполнения
Failed to parse XML configuration from network_security_config
что я должен сделать, чтобы решить это?
у меня есть разрешение ИНТЕРНЕТ на моем манифесте.
Я пытался найти что-то похожее по другим вопросам и не смог найти ответ.
Я пытался следовать этому уроку: https://www.youtube.com/watch?v=53BsyxwSBJk
но кажется, что с XML есть какая-то проблема, но я ее не понимаю.
вот мой класс:
class TestActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test)
val adapter = ArrayAdapter<User>(this, android.R.layout.simple_list_item_1)
listViewTest.adapter = adapter
val url = URL(myapi)
val request = Request.Builder().url(url).build()
val client = OkHttpClient()
client.newCall(request).enqueue(object: Callback {
override fun onResponse(call: Call, response: Response) {
val body = response.body.toString()
println(body)
}
override fun onFailure(call: Call, e: IOException) {
}
} )
}
}
мой журнал ошибок:
2019-07-04 15:11:30.822 3994-3994/com.eldareini.kotlin.meet4match E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.eldareini.kotlin.meet4match, PID: 3994
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.eldareini.kotlin.meet4match/com.eldareini.kotlin.meet4match.TestActivity}: java.lang.RuntimeException: Failed to parse XML configuration from network_security_config
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.RuntimeException: Failed to parse XML configuration from network_security_config
at android.security.net.config.XmlConfigSource.ensureInitialized(XmlConfigSource.java:89)
at android.security.net.config.XmlConfigSource.getPerDomainConfigs(XmlConfigSource.java:55)
at android.security.net.config.ManifestConfigSource.getPerDomainConfigs(ManifestConfigSource.java:45)
at android.security.net.config.ApplicationConfig.ensureInitialized(ApplicationConfig.java:175)
at android.security.net.config.ApplicationConfig.getTrustManager(ApplicationConfig.java:120)
at android.security.net.config.RootTrustManagerFactorySpi.engineGetTrustManagers(RootTrustManagerFactorySpi.java:65)
at javax.net.ssl.TrustManagerFactory.getTrustManagers(TrustManagerFactory.java:301)
at okhttp3.internal.platform.Platform.platformTrustManager(Platform.kt:85)
at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:211)
at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:204)
at com.eldareini.kotlin.meet4match.TestActivity.onCreate(TestActivity.kt:41)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.security.net.config.XmlConfigSource$ParserException: Unknown certificates src. Should be one of system|user|@resourceVal at: Binary XML file line #6
at android.security.net.config.XmlConfigSource.parseCertificatesEntry(XmlConfigSource.java:193)
at android.security.net.config.XmlConfigSource.parseTrustAnchors(XmlConfigSource.java:208)
at android.security.net.config.XmlConfigSource.parseConfigEntry(XmlConfigSource.java:262)
at android.security.net.config.XmlConfigSource.parseNetworkSecurityConfig(XmlConfigSource.java:325)
at android.security.net.config.XmlConfigSource.ensureInitialized(XmlConfigSource.java:83)
at android.security.net.config.XmlConfigSource.getPerDomainConfigs(XmlConfigSource.java:55)
at android.security.net.config.ManifestConfigSource.getPerDomainConfigs(ManifestConfigSource.java:45)
at android.security.net.config.ApplicationConfig.ensureInitialized(ApplicationConfig.java:175)
at android.security.net.config.ApplicationConfig.getTrustManager(ApplicationConfig.java:120)
at android.security.net.config.RootTrustManagerFactorySpi.engineGetTrustManagers(RootTrustManagerFactorySpi.java:65)
at javax.net.ssl.TrustManagerFactory.getTrustManagers(TrustManagerFactory.java:301)
at okhttp3.internal.platform.Platform.platformTrustManager(Platform.kt:85)
at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:211)
at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:204)
at com.eldareini.kotlin.meet4match.TestActivity.onCreate(TestActivity.kt:41)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)