daniele110696
Nuovo Utente
- Messaggi
- 11
- Reazioni
- 0
- Punteggio
- 22
salve, ho un problema con il metodo main di questo programma, il quale lancia in esecuzione NoSuch
ElementException per la riga con asterischi appena dopo l'inizio del primo ciclo while. dove ho sbagliato?
import java.io.*;
import java.util.Scanner;
public class TraduttoreTester
{ public static void main(String[] args) throws IOException
{
if(args.length!= 2)
{
System.out.println("uso : inserire 2 nomi di file di testo");
System.exit(1);
}
Traduttore trad1 = new Traduttore();
Scanner file1 = new Scanner(new FileReader(args[0]));
while(file1.hasNextLine())
{
String line = file1.nextLine();
Scanner linescan = new Scanner(line); ******
String word = linescan.next();//parola: campo "key" del dizionario
linescan.next();//salto i "due punti"
int i = 0;
String[] transl = new String[1]; //inserisco le traduzioni in
while(linescan.hasNext()) //un array di stringhe transl
{
if (i == transl.length) // aggiungo un elemento all'array
{ String[] newtransl = new String[transl.length +1];
System.arraycopy(transl, 0, newtransl, 0, transl.length);
transl= newtransl;
}
transl[i++] = linescan.next(); //(campo "value" del dizionario)
}
trad1.insert(word, transl);
}
System.out.println(trad1);
ElementException per la riga con asterischi appena dopo l'inizio del primo ciclo while. dove ho sbagliato?
import java.io.*;
import java.util.Scanner;
public class TraduttoreTester
{ public static void main(String[] args) throws IOException
{
if(args.length!= 2)
{
System.out.println("uso : inserire 2 nomi di file di testo");
System.exit(1);
}
Traduttore trad1 = new Traduttore();
Scanner file1 = new Scanner(new FileReader(args[0]));
while(file1.hasNextLine())
{
String line = file1.nextLine();
Scanner linescan = new Scanner(line); ******
String word = linescan.next();//parola: campo "key" del dizionario
linescan.next();//salto i "due punti"
int i = 0;
String[] transl = new String[1]; //inserisco le traduzioni in
while(linescan.hasNext()) //un array di stringhe transl
{
if (i == transl.length) // aggiungo un elemento all'array
{ String[] newtransl = new String[transl.length +1];
System.arraycopy(transl, 0, newtransl, 0, transl.length);
transl= newtransl;
}
transl[i++] = linescan.next(); //(campo "value" del dizionario)
}
trad1.insert(word, transl);
}
System.out.println(trad1);