dialogflow / dialogflow-android-client

Android SDK for Dialogflow
https://dialogflow.com
Apache License 2.0
575 stars 270 forks source link

Caused by: java.lang.NumberFormatException: For input string: "simple_response" #43

Closed NinhvanLuyen closed 7 years ago

NinhvanLuyen commented 7 years ago

When i Send a message to API.AI server and client blink to error below :

java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:325) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) Caused by: java.lang.NumberFormatException: For input string: "simple_response" at java.lang.Integer.parseInt(Integer.java:521) at java.lang.Integer.parseInt(Integer.java:556) at com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:260) at ai.api.GsonFactory$ResponseItemAdapter.deserialize(GsonFactory.java:78) at ai.api.GsonFactory$ResponseItemAdapter.deserialize(GsonFactory.java:71) at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:69) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) at com.google.gson.Gson.fromJson(Gson.java:887) at com.google.gson.Gson.fromJson(Gson.java:852) at com.google.gson.Gson.fromJson(Gson.java:801) at com.google.gson.Gson.fromJson(Gson.java:773) at ai.api.AIDataService.request(AIDataService.java:193) at ai.api.AIDataService.request(AIDataService.java:148) at ai.api.AIDataService.request(AIDataService.java:124) at ninhv.vl.vlchat.views.chat.ChatActivity$1.doInBackground(ChatActivity.java:90) at ninhv.vl.vlchat.views.chat.ChatActivity$1.doInBackground(ChatActivity.java:85) at android.os.AsyncTask$2.call(AsyncTask.java:305) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)  at java.lang.Thread.run(Thread.java:761) 

And here is code in doInBackground method @Override protected AIResponse doInBackground(AIRequest... requests) { AIRequest request = requests[0]; try { Log.e("REQUEST",request.toString()); return aiDataService.request(request); } catch (AIServiceException e) { } return null; }

johnpeterflynn commented 7 years ago

My team encountered the exact same crash as of yesterday.

This problem appears to occur on Android when an agent uses an intent with a default text response (no webhook). We fixed it by using a webhook to fulfill all of our intents.

Aashit-Sharma commented 7 years ago

Same issue. wondering if someone knows the fix...

vishalkharat commented 7 years ago

@johnflynn90 Same issue we are facing. Can you please share fix?

tao1 commented 7 years ago

Same here

johnpeterflynn commented 7 years ago

Hi @vishalkharat ,

We didn't really fix it. We avoided the crash by only using webhooks to generate responses to intents.

When creating an intent in API.AI you have the option to check "use webhook" instead of using text responses. My team found that the crash only occurs when we used the local API.AI text responses. We modified all of our intents to use webhooks so that our fulfillment server would generate text responses. I don't know why this works; we discovered it through trial and error.

If you don't have a fulfillment server (e.g. your agent lives entirely in API.AI) then this solution won't work for you.

vishalkharat commented 7 years ago

@johnflynn90 Thanks for reply.

I think this can be fixed by updating libai sdk. As api.ai is sending messages object in two formats as part of response. Because of this android app fails to map these objects, and results in a crash. Following is the sample response. "messages":[ { "type":"simple_response", "platform":"google", "textToSpeech":"sample text to convert" }, { "type":0, "speech":"sample text to convert" } ]

Aashit-Sharma commented 7 years ago

Updating libai sdk how ? I am using the latest 1.4.8 in my build gradle , still this issue. I think the issue lies in the onResult method I may be wrong though

folomeev commented 7 years ago

Hello friends!

Please no worries, we are working on problem!

Thank you for your patience

folomeev commented 7 years ago

The issue was fixed in Java SDK and will be available on next release.

SidCosineLabs commented 7 years ago

When is the next release coming for android because I am now frequently getting this issue in my android app. And if you can tell me any workaround please let me know. Thanks

folomeev commented 7 years ago

There is a kind of workaround. You may manually build and install Java SDK from GitHub repository:

git clone https://github.com/api-ai/apiai-java-client.git
cd apiai-java-client/
mvn install

This commands will checkout the code, build it and install library of version 1.4.9 into your local maven repository.

Next step is to change dependency version in your build.gradle file:

find line

compile 'ai.api:libai:1.4.8'

and replace it with

compile 'ai.api:libai:1.4.9'

rebuild your project.

SidCosineLabs commented 7 years ago

Hi,

Thanks for the workaround, I did what you said and compiled the new dependency and now when I am running the app its giving me two errors 1 Noclassdeffound error 2 ScriptManager error

Could you please tell me how to fix this.

Thanks

On Fri, Jun 23, 2017 at 3:35 PM, folomeev notifications@github.com wrote:

There is a kind of workaround. You may manually build and install Java SDK from GitHub repository:

git clone https://github.com/api-ai/apiai-java-client.gitcd apiai-java-client/ mvn install

This commands will checkout the code, build it and install library of version 1.4.9 into your local maven repository.

Next step is to change dependency version in your build.gradle file:

find line

compile 'ai.api:libai:1.4.8'

and replace it with

compile 'ai.api:libai:1.4.9'

rebuild your project.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/api-ai/apiai-android-client/issues/43#issuecomment-310626832, or mute the thread https://github.com/notifications/unsubscribe-auth/AbKcR0IaHPEuKt2Zjtg9SwMdeSxSUVdLks5sG43mgaJpZM4NyU31 .

-- Siddhant Panhalkar Senior Android Developer Cosine Labs https://cosinelabs.com/

folomeev commented 7 years ago

I've build apiAISampleApp application and everything was fine. Would you be so kind to provide the call stack traces?

SidCosineLabs commented 7 years ago

When I am creating aidataservice object, its crashing on this below line. When I use your these below dependency it doesn't crash

compile 'ai.api:libai:1.4.8' compile 'ai.api:sdk:2.0.5@aar'

aiDataService = new AIDataService(this, config);

On Fri, Jun 23, 2017 at 6:40 PM, folomeev notifications@github.com wrote:

I've build apiAISampleApp application and everything was fine. Would you be so kind to provide the call stack traces?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/api-ai/apiai-android-client/issues/43#issuecomment-310661292, or mute the thread https://github.com/notifications/unsubscribe-auth/AbKcR354titVJLAy8l5r3CHsL2fM9-83ks5sG7lKgaJpZM4NyU31 .

-- Siddhant Panhalkar Senior Android Developer Cosine Labs https://cosinelabs.com/

HoiJean commented 7 years ago

Hello everyone, i am still facing the same issue "Caused by: java.lang.NumberFormatException: Invalid int: "simple_response" " Before result the app crashes and i get that error on the console, see below the full error output:

AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: nl.nanomedia.virtuala, PID: 27568 java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:300) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355) at java.util.concurrent.FutureTask.setException(FutureTask.java:222) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.NumberFormatException: Invalid int: "simple_response" at java.lang.Integer.invalidInt(Integer.java:138) at java.lang.Integer.parse(Integer.java:410) at java.lang.Integer.parseInt(Integer.java:367) at java.lang.Integer.parseInt(Integer.java:334) at com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:260) at ai.api.GsonFactory$ResponseItemAdapter.deserialize(GsonFactory.java:78) at ai.api.GsonFactory$ResponseItemAdapter.deserialize(GsonFactory.java:71) at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:69) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220) at com.google.gson.Gson.fromJson(Gson.java:887) at com.google.gson.Gson.fromJson(Gson.java:852) at com.google.gson.Gson.fromJson(Gson.java:801) at com.google.gson.Gson.fromJson(Gson.java:773) at ai.api.AIDataService.request(AIDataService.java:193) at ai.api.AIDataService.request(AIDataService.java:148) at ai.api.services.GoogleRecognitionServiceImpl$2.doInBackground(GoogleRecognitionServiceImpl.java:166) at ai.api.services.GoogleRecognitionServiceImpl$2.doInBackground(GoogleRecognitionServiceImpl.java:158) at android.os.AsyncTask$2.call(AsyncTask.java:288)

tao1 commented 7 years ago

This error came back about 2 or 3 days. But this bug had disappeared for about 2 weeks before that.

folomeev commented 7 years ago

Fixed. Please update dependency version up to 2.0.6:

compile 'ai.api:sdk:2.0.6@aar'
SidCosineLabs commented 7 years ago

I updated the dependency again setting the custom session id in AIRequest object, than also its not happening.

AIRequest request = new AIRequest(); request.setSessionId(MyData.getInstance(MyApplication.getInstance()).getGatewayId()

Please let me know any fix or workaround because I need to make it work as soon as possible.

Thank you

On Sat, Jul 8, 2017 at 9:52 AM, folomeev notifications@github.com wrote:

Closed #43 https://github.com/api-ai/apiai-android-client/issues/43.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/api-ai/apiai-android-client/issues/43#event-1155387202, or mute the thread https://github.com/notifications/unsubscribe-auth/AbKcRzDM5K08y44h76M04NHmAXNld_6nks5sLwQCgaJpZM4NyU31 .

-- Siddhant Panhalkar Senior Android Developer Cosine Labs https://cosinelabs.com/

RabbiHasanR commented 6 years ago

Hello everyone, i facing error " Caused by: java.lang.NumberFormatException:For input string: "Rabbi"". Before the app crashes i get the following error: 2018-03-31 20:42:53.448 32009-32066/com.example.diu.pointofsale E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3 Process: com.example.diu.pointofsale, PID: 32009 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:318) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354) at java.util.concurrent.FutureTask.setException(FutureTask.java:223) at java.util.concurrent.FutureTask.run(FutureTask.java:242) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:761) Caused by: java.lang.NumberFormatException: For input string: "Rabbi" at java.lang.Integer.parseInt(Integer.java:521) at java.lang.Integer.parseInt(Integer.java:556) at com.example.diu.pointofsale.Database.DatabaseHelper.getAllUser(DatabaseHelper.java:267) at com.example.diu.pointofsale.Activity.AdminHomeActivity$2.doInBackground(AdminHomeActivity.java:108) at com.example.diu.pointofsale.Activity.AdminHomeActivity$2.doInBackground(AdminHomeActivity.java:104) at android.os.AsyncTask$2.call(AsyncTask.java:304) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)  at java.lang.Thread.run(Thread.java:761) 

Please help me how to fix it..