RISOLTO Problema in ESECUZIONE java

Stato
Discussione chiusa ad ulteriori risposte.

daniele110696

Nuovo Utente
11
0
il codice compila correttamente, ma in esecuzione non riapre lo scanner nell'ultima parte, dove
dovrei fare l'inserimento. in particolare genera i seguenti errori, come se invece avessi inserito qualcosa, dove sbaglio?

Exception in thread "main" DictionaryItemNotFoundException
at Studenti.binarySearch(StudentiTester.java:143)
at Studenti.binarySearch(StudentiTester.java:150)
at Studenti.binarySearch(StudentiTester.java:150)
at Studenti.binarySearch(StudentiTester.java:150)
at StudentiTester.main(StudentiTester.java:61)

Codice:
import java.io.*;
import java.util.Scanner;
public class StudentiTester
{   public static void main(String[] args)
    {
      if(args.length!=2)
     {
         System.out.println("uso: inserire i nomi di 2 file di testo");
         System.exit(1);
     }
     
     String filename1 = args[0];
     String filename2 = args[1];
     Scanner file1 = null;
     try
     {
         file1 = new Scanner(new FileReader(filename1));
     }
     
     catch(FileNotFoundException e)
     {
         System.out.println("problemi in apertura del file1!");
     }
     
     Studenti stud1 = new Studenti();
     Studenti stud2 = new Studenti();
     
     while(file1.hasNextLine())
     {
         String line = file1.nextLine();
         Scanner linescan = new Scanner(line);
         linescan.useDelimiter(":");
         while(linescan.hasNextLine())
         {
             String mat = (linescan.next());
             long matricola = Long.parseLong(mat);
             String nome = linescan.nextLine();
             stud1.insert(matricola, (Object) nome);
         }
     }
     
     System.out.println(stud1);
     file1.close();
     Scanner in = new Scanner(System.in);
     boolean done = false;
     while(!done)
     {
         System.out.println("inserire una chiave da cercare, Q per uscire");
         String p = in.nextLine();
         if(p.equalsIgnoreCase("Q"))
             done = true;
         
         else
         {
         try
         {
             long chiave = Long.parseLong(in.next());
             Object nome = stud1.find(chiave);
             stud2.insert(chiave, nome);
             stud1.remove(chiave);
         }
         
         catch(NumberFormatException e)
         {
             System.out.println("inserire una chiave corretta!");
         }
         }
     }         
         
     // ....... da completare ............
    }
}
[CODE]
 

rodhellas

Utente Èlite
1,522
427
CPU
Ryzen 5 3600
Dissipatore
GELID Phantom
Scheda Madre
MSI B450 Gaming Plus Max
HDD
500GB m.2 + 2TB HDD
RAM
16GB Corsair LPX 3000mhz
GPU
Gigabyte GTX 960 OC
Audio
Integrata
Monitor
SyncMaster 223BW
PSU
Antec HCG-520M
Case
Meshify C
Net
Gigabit Fastweb
OS
Windows 10 64bit
Difficile aiutarti se non posti il codice del binarySearch. Supponendo sia lo stesso dell'altro post, probabilmente pos è < 0 e lancia quindi la "DictionaryItemNotFoundException" (che suppongo significhi che non c'è l'elemento del dizionario)
 

daniele110696

Nuovo Utente
11
0
Risolto, usavo la redirezione dell'input su un file di testo che era stato incolonnato in modo errato dall'editor. No binarysearch lo avevo corretto, ho inserito la cattura dell'eccezione
Grazie


Inviato dal mio iPhone utilizzando Toms Hardware Italia Forum
 
Stato
Discussione chiusa ad ulteriori risposte.

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!