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!");
Run Code Online (Sandbox Code Playgroud)
我发现了一个错误.(无法在Java中调用数组类型String [])上的addObject(String),其中questionArray,answerArray,subQuestionAray,statementArray是字符串数组,还有什么可以使用而不是addobject?我正在使用Eclipse helios在Android上开发游戏.
将项添加到a的正确方法String[]是使用索引:
String[] questionArray = new String[5]; //if there are five questions
questionArray[0] = "Hi honey, I just got to work. What are you upto?";
Run Code Online (Sandbox Code Playgroud)
或者,如果您事先不知道数组的大小,请使用ArrayList,当您添加更多项时,ArrayList会自动增大.
List<String> questionList = new ArrayList<String>();
questionList.add("Hi honey, I just got to work. What are you upto?");
Run Code Online (Sandbox Code Playgroud)