如何解决android编程
|questionArray.addObject(\"Hi honey,I just got to work. What are you upto?\");
answerArray.addObject(\"I was just thinking about you darling.:Just missing you from the time you left.:I was just going through our wedding photos.:Well right now,just talking to you & its giving me a headache.:Nothing much I was just texting my ex-boyfriend.\");
subQuestionArray.addObject(\"What do you mean by that?\");
subAnswerArray.addObject(\"Oh nothing dear,just missing you.:Nothing,just that I think dumping my ex was a mistake.\");
statementArray.addObject(\"Good to know,I\'ve work to do,BYE!\");
我开始出错。 (无法在数组类型String []上调用addObject(String))
在Java中,questionArray,answerArray,subQuestionAray,statementArray是字符串数组,除了addobject还能使用什么?
我正在使用Eclipse helios在Android上开发游戏。
解决方法
将项目添加到“ 1”的正确方法是使用索引:
String[] questionArray = new String[5]; //if there are five questions
questionArray[0] = \"Hi honey,I just got to work. What are you upto?\";
或者,如果您事先不知道数组的大小,请使用ArrayList,随着添加更多项,该数组的大小会自动增加。
List<String> questionList = new ArrayList<String>();
questionList.add(\"Hi honey,I just got to work. What are you upto?\");
,您无法将对象添加到Java数组中。数组具有固定的宽度。您应该改用List <>或Vector <>。
,也许您应该考虑改用List<String> questionList = new ArrayList<String>()
?
数组的大小不是动态的,您不能仅添加超出数组大小的对象。使用类似列表或向量的集合。
,使questionArray等成为
向量= new Vector();
要么
ArrayList = new ArrayList();
并使用添加项目
.add(对象o)
方法代替。那将解决您所有的问题:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。