Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Kotlin Android中使用Apollo客户端使用GraphQL API执行HTTP调用_Android_Kotlin_Graphql_Apollo Client - Fatal编程技术网

无法在Kotlin Android中使用Apollo客户端使用GraphQL API执行HTTP调用

无法在Kotlin Android中使用Apollo客户端使用GraphQL API执行HTTP调用,android,kotlin,graphql,apollo-client,Android,Kotlin,Graphql,Apollo Client,我正在使用Kotlin开发一个Android应用程序。我试图在我的应用程序中使用Apollo客户端来使用GraphQLAPI。我安装了Apollo客户端并成功地生成了模式和类。现在我发出了一个变异请求,但它没有返回任何响应 这是我的密码 view.btn_login.setOnClickListener { val okHttp = OkHttpClient .Builder() .addIntercepto

我正在使用Kotlin开发一个Android应用程序。我试图在我的应用程序中使用Apollo客户端来使用GraphQLAPI。我安装了Apollo客户端并成功地生成了模式和类。现在我发出了一个变异请求,但它没有返回任何响应

这是我的密码

view.btn_login.setOnClickListener {
            val okHttp = OkHttpClient
                .Builder()
                .addInterceptor({ chain ->
                    val original = chain.request()
                    val builder = original.newBuilder().method(original.method(),
                        original.body())
                    chain.proceed(builder.build())
                })
                .build()
            val apolloClient = ApolloClient.builder()
                .serverUrl("https://my-app-name.herokuapp.com/graphql")
                .okHttpClient(okHttp)
                .build()

            val loginMutation = LoginMutation.builder()
                .identity(view.etf_email.text.toString())
                .password(view.etf_password.text.toString())
                .build()

            view.tv_login_error_message.text = "Started making request"
            apolloClient.mutate(loginMutation).enqueue(object: ApolloCall.Callback<LoginMutation.Data>() {
                override fun onFailure(e: ApolloException) {
                    view.tv_login_error_message.text = e.message
                }

                override fun onResponse(response: Response<LoginMutation.Data>) {
                    view.tv_login_error_message.text = "Request completed."
                }
            })
        }

查看您发布的stacktrace后,我认为错误的实际原因如下:

原因:java.net.UnknownHostException:无法解析主机


您的设备似乎无法通过DNS解析服务器URL。这意味着您的DNS服务器可能无法访问,或者您输入了错误的服务器URL,或者您的设备由于某种原因(例如防火墙)无法访问DNS服务器。我会在设备内部打开一个浏览器并尝试连接到服务器(这样我就可以建立连接)

你能提供一些关于错误信息的更多信息吗?它是由
onFailure
回调方法生成的吗?如果是,则方法中的异常可能包含有关出错原因的有用信息。您还应该验证(如果可能的话)服务器是否收到了您的请求。这是来自ApolloException的错误消息。我将尝试打印异常的完整堆栈跟踪,以获取有关实际错误的更多详细信息。内部异常通常包含异常的真正原因。您好@gmetal,我刚刚更新了添加stacktrace详细信息的问题。@WaiYanHein您检查了Heroku中的日志了吗?你的应用正在运行吗?嗨,谢谢你的回答。是的,我刚刚注意到我的模拟器wifi没有显示internet,因为它由于某种原因无法解析DNS。我刚刚连接到我的手机热点,它现在正在工作。
<uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.CAMERA"/>
2019-09-15 22:54:13.027 20508-20580/com.example.memento E/MYAPP: exception
2019-09-15 22:54:13.027 20508-20580/com.example.memento W/System.err: com.apollographql.apollo.exception.ApolloNetworkException: Failed to execute http call
2019-09-15 22:54:13.028 20508-20580/com.example.memento W/System.err:     at com.apollographql.apollo.internal.interceptor.ApolloServerInterceptor$2.onFailure(ApolloServerInterceptor.java:120)
2019-09-15 22:54:13.028 20508-20580/com.example.memento W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:211)
2019-09-15 22:54:13.028 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
2019-09-15 22:54:13.028 20508-20580/com.example.memento W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.lang.Thread.run(Thread.java:919)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err: Caused by: java.net.UnknownHostException: Unable to resolve host "memento-nova-api-staging.herokuapp.com": No address associated with hostname
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:156)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:103)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at java.net.InetAddress.getAllByName(InetAddress.java:1152)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.Dns$1.lookup(Dns.java:40)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:185)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.java:149)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.RouteSelector.next(RouteSelector.java:84)
2019-09-15 22:54:13.029 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:214)
2019-09-15 22:54:13.030 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
2019-09-15 22:54:13.031 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
2019-09-15 22:54:13.032 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:250)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:201)
2019-09-15 22:54:13.033 20508-20580/com.example.memento W/System.err:   ... 4 more
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err: Caused by: android.system.GaiException: android_getaddrinfo failed: EAI_NODATA (No address associated with hostname)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at libcore.io.Linux.android_getaddrinfo(Native Method)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at libcore.io.BlockGuardOs.android_getaddrinfo(BlockGuardOs.java:200)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at libcore.io.ForwardingOs.android_getaddrinfo(ForwardingOs.java:74)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:     at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:135)
2019-09-15 22:54:13.036 20508-20580/com.example.memento W/System.err:   ... 26 more