0

コードの実行時に問題が発生しています。正常にコンパイルされますが、実行するとこのエラーが発生します。data3.txt ファイルは一連の数字です。

エラー:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at database3.main(database3.java:6)

私のコード:

import java.io.*;
import java.util.*;
public class  database3 {
public static void main(String[] args) {

File inputDataFile = new File(args[0]);
Scanner inputFile = new Scanner("data3.txt"); // READ DATA FROM FILE   
int foundvalue = 0;
int d = inputFile.nextInt();
int list[] = new int[d];

for (int i = 0; i < d; i++)
    list[i] = inputFile.nextInt();


System.out.println("Database Server is Ready for Number Lookups!");

Scanner stdin = new Scanner(System.in); //Get user input
double input;
while (stdin.hasNext()){
  input = stdin.nextDouble();
  boolean found = false;
  System.out.println("The number to look up is: " +input);

  for (int j = 0; j < d; j++){
     if(list[j] == input){
        found = true;  
        break;   
     }    
  }
  if(found == true){
     System.out.println(input +" is in the database");
  }
  else{
     System.out.println(input +" is NOT in the database");
  }
}

System.out.println("Goodbye!");
System.exit(0);

}     
}
4

4 に答える 4