【发布时间】:2019-05-16 03:46:49
【问题描述】:
我正在编写一个类似于 java 飞机事实示例的简单技能,但我有两个奇怪的行为:
1) 一个意图中的相同代码可以正常工作,但在另一个意图中会导致错误;
2) 我无法从公共静态列表中删除元素! 我将尝试用一个非常接近的例子来更好地解释。 我有两个可以调用的意图: - 行动意图; - 停止意图。
第一个意图检索从类常量中检索到的列表(List 类型)并返回随机 CustomObject 的属性—— 这工作正常。 然后它应该将该对象设置为 Session Attributes 并将其从列表中删除,因为下一次响应应该是最后一个 CustomObject 的第二个属性加上新 CustomObject 的第一个属性。有意义吗?
代码如下:
// this row works correctly on the other intent
Map<String, Object> sessionAttributes = input.getAttributesManager().getSessionAttributes();
CustomObject last=(sessionAttributes.get("last")!=null) ? (CustomObject)sessionAttributes.get("last") : null;
List<CustomObject> allObjects = MAPPER.convertValue(Constants.getAllObjects(), List.class);
int index = new Random().nextInt(tutti.size());
CustomObject new = allObjects.get(index);
// a simple method that contains allObjects.remove(index) because it didn't work here but also this cause an error
Constants.removeCustomObjectFromList(index);
sessionAttributes.put("ultimoNome", nuovoNome);
String title = Constants.SKILL_TITLE;
String primaryText =new.getTrue();
String secondaryText =(last!=null) ?last.getFalse() : "";
String speechText = "" + secondaryText + " "+primaryText + "?";
return input.getResponseBuilder()
.withSpeech(speechText)
.withSimpleCard(title, primaryText)
.withReprompt(speechText)
.build();
如果我注释掉链接到 sessionAttribute 和 Constants.removeCustomObjectFromList 的行,它可以正常工作,但是正如我所说,对 sessionAttribute 的引用在另一个意图中可以正常工作,我必须从我的初始列表中删除 CustomObjects,因为用户应该听两次同样的事情! 有人能告诉我在哪里可以找到关于这个主题的好信息吗?
【问题讨论】:
标签: java aws-lambda alexa-skills-kit