java - Why am i getting NoSuchElementException error in my class -
I have this class, which in the north should open the file with a question in response to NR. The problem occurs when I get to write in ArrayList, I've tried all types of Arrayists, Linkedists, Even Vectors. Answers to the first part of the file, such as questions and answers, it takes no problem. But when I want to store those answers in a list, I can save that list in an object. It will not work.
If someone can help with this or knows a better way then an unknown NR string in an object list will be epic.
The file format is:
A question, 3, yes, no, maybe another question, 4, yes, maybe, no, why not < / Pre> my class:
public square GetSurvey {intrebare public static string; Static en raspasauri; Public static int i = 1; Fixed string holder; // static string [] rasp = new string [250]; Fixed list & lt; String & gt; Rasp = new linked list & lt; String & gt; (); Public stable SurveyClass [] obj = new SurveyClass [250]; Public static zero loadserve () {file file = new file (environment GateInstinestorporical Directory (environment. DIRECTORY_DOWNLOADS) + file. Separator + "surveyet."); If (! File.exists ()) {try {file.createNewFile ()}} hold (IOException e) {e.printStackTrace (); }} If (file.exists ()) {try {scanner read = new scanner (file); Read.useDelimiter (","); While (read.hasNext ()) {intrebare = read.next (); String raspunsuri1 = read.next (); //Log.w("Date".String.valueOf(raspunsuri)); //obj[i].setNrRasp(raspunsuri); For (int j = 0; j & lt; 3; j ++) {log. W ("date", string.valouf (j)); Rasp.add (j, read.next ()); } String [] stringArr = rasp.toArray (new string [rasp.size ()]); Log.w ("date", stringArr [i]); //obj[i].setRaspunsuri(rasp); Rasp.clear (); I ++; }} Hold (IOException e) {e.printStackTrace (); }}}}
You can read.next (3 times) inside your loop So that means that you get past at the end of the input, hence NoSuchElementException
use it only once and allocate it in a local variable inside the loop, so that you You can also use the value when you need it later in the loop.
Comments
Post a Comment