0

I am trying to integrate the amozon alexa. I have implemented like below code.

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);
    }
};

Here if I login with the amazon and then pass the token and refresh token it's working. Later if I reboot the device then device shutdown and throwing this exception.

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)

Please suggest the solution for this.

AngelJanniee
  • 613
  • 1
  • 11
  • 30

0 Answers0