java.lang.NullPointerException:尝试调用虚方法' okhttp3.ConnectionPool okhttp3.OkHttpClient.connectionPool()

时间:2017-12-15 02:25:06

标签: android okhttp3 alexa-voice-service

我正在尝试整合amozon alexa。 我已经实现了类似下面的代码。

private CountDownTimer pingTimer = new CountDownTimer(30000, 3000) {
    @Override
    public void onTick(long millisUntilFinished) {
        try {
            InetAddress address = InetAddress.getByName(CloudConfig.ALEXA_HOST_US);
            this.cancel();

            TokenManager.getAccessToken(mContext, new TokenManager.TokenCallback() {
                @Override
                public void onSuccess(String token) {
                    Log.i(TAG, "Logged in to Amazon");
                    mHTTPClient = ClientUtil.getTLS12OkHttpClient();
                    establishDownChannel(token);
                    Log.i(TAG, "Refresh token : " + token);
                }

                @Override
                public void onFailure(Throwable e) {
                    Log.e(TAG, "Not Logged In failed" + e);

                }
            });
        } catch (UnknownHostException exc) {
            Log.e(TAG, "Unable to resolve Amazon host, retrying...");
        }
    }

    public void onFinish() {
        mTTS.speak("Voice error", TTSHelper.UTTERANCE_ALEXA_FAIL);
    }
};

如果我使用亚马逊登录然后传递令牌并刷新令牌,那么它正在工作。稍后,如果我重新启动设备,然后设备关闭并抛出此异常。

FATAL EXCEPTION: main
                                                             Process: tw.com.test.wear, PID: 1638
                                                             java.lang.NullPointerException: Attempt to invoke virtual method 'okhttp3.ConnectionPool okhttp3.OkHttpClient.connectionPool()' on a null object reference
                                                                 at tw.com.test.cloud.AlexaClient$1$1.onFailure(AlexaClient.java:138)
                                                                 at com.willblaschko.android.alexa.TokenManager.getAccessToken(TokenManager.java:193)
                                                                 at tw.com.test.cloud.AlexaClient$1.onTick(AlexaClient.java:126)
                                                                 at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:133)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                 at android.os.Looper.loop(Looper.java:135)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)

请为此建议解决方案。

0 个答案:

没有答案