androidthings / sample-googleassistant

Google Assistant API sample for Android Things
Apache License 2.0
467 stars 147 forks source link

Null pointer moving from v1alpha1 to v1alpha2 #57

Closed mrcartier closed 6 years ago

mrcartier commented 6 years ago

Thanks for update to new endpoints. Having issue running the sample app with latest update to v1alpha2 though. There's a null pointer issue...

Caused by: java.lang.NullPointerException 
   at com.google.assistant.embedded.v1alpha2.DeviceConfig.setDeviceId(DeviceConfig.java:73)
   at com.google.assistant.embedded.v1alpha2.DeviceConfig.access$100(DeviceConfig.java:13)
   at com.google.assistant.embedded.v1alpha2.DeviceConfig$Builder.setDeviceId(DeviceConfig.java:356)
   at com.example.androidthings.assistant.EmbeddedAssistant$Builder.build(EmbeddedAssistant.java:622)
   at com.example.androidthings.assistant.AssistantActivity.onCreate(AssistantActivity.java:211)
   at android.app.Activity.performCreate(Activity.java:7000)
   at android.app.Activity.performCreate(Activity.java:6991)

DeviceConfig.java 73, 13 & 356 are build files & as per studio shouldn't be edited. For EmbeddedAssitant.java:622, is it related to lines 524 (setDeviceModelId) & 535 (setDeviceInstanceId)? For me both of those methods are greyed out; when I hover over them studio tells me

Method 'setDeviceModelId(java.lang.String)' is never used

and I'm not really certain how to call them in AssistantActivity.java somewhere ~line 152. Made certain to recreate res > raw > credentials.json & when I run the old sample (v1alpha1) it still works so I think everything is OK as far as project settings. As best I can tell, I added everything necessary for the move to alpha2?

Fleker commented 6 years ago

In the EmbeddedAssistant.builder, you'll need to add the setDeviceModelId and setDeviceInstanceId: https://github.com/androidthings/sample-googleassistant/blob/master/app/src/main/java/com/example/androidthings/assistant/AssistantActivity.java#L152

mrcartier commented 6 years ago

Thanks for the reply. It's working now.

anishu23 commented 6 years ago

What should the parameters be for these methods? I am confused. Am I doing it wrong?

Fleker commented 6 years ago

They should be the device model and instance that you register as part of the Assistant SDK setup, although they can technically be any string if you aren't interested in handling device actions.