У меня проблема с массивом...
Привет ,
У меня есть проблема с массивом
Я читаю информацию из txt
эта информация:
4 5 3 4 3 Add_Course CPCS202 CPCS203 CPCS204 CPCS353 Add_ExamType Exam1 Exam2 FinalExam LabExams Assignments Quiz Add_Student_For_ourse 0 Fatima Laila Maryam Khalida Zayneb Add_Student_For_Course 1 Waleed Rashid Hassan Add_Student_For_Course 2 Shahid Yusuf Rami Sohail Add_Student_For_Course 3 Hina Reem Mona Add_Marks 9 15 23 14 25 5 8 13 18 13 28 4 7 12 16 12 23 5 8 12 15 10 22 3 5 11 15 11 20 2 8 13 24 13 24 5 7 15 23 14 30 5 3 10 20 12 22 5 9 15 25 14 28 4 8 14 24 15 26 5 9 15 23 13 27 5 6 12 22 15 29 4 3 10 22 12 25 3 7 15 23 13 28 4 8 13 24 14 23 5
Проблема заключается в том, что при использовании 3-мерного массива
в этом коде :
Array3D[i][j][k] = t.nextInt();
{ Exception in thread "main" java.lang.NullPointerException }
Что я уже пробовал:
public static void main(String[] args) throws FileNotFoundException { String[] FCourse, SCourse, TCourse, FourCourse; File f = new File("C:\\Users\\WCortex\\Desktop\\EA_1741415_P1_ExamGradingProgram_Main\\input.txt"); Scanner t = new Scanner(f); if (!(f.exists())) { System.out.println("File Not found!"); System.exit(0); } while (t.hasNextLine()) { String FLine = t.next(); //get 4 int ToInt = Integer.parseInt(FLine); t.nextLine(); String[] NumberOfStudents0 = new String[t.nextInt()]; //5 String[] NumberOfStudents1 = new String[t.nextInt()]; //3 String[] NumberOfStudents2 = new String[t.nextInt()]; //4 String[] NumberOfStudents3 = new String[t.nextInt()]; //3 int[]n={NumberOfStudents0.length,NumberOfStudents1.length,NumberOfStudents2.length,NumberOfStudents3.length}; int[][][] Array3D = new int[ToInt][][]; String[] Course = new String[ToInt]; //Number of Course "4" String[] ExamType = new String[6]; String Line1 = t.next(); //Add_Course //Do Array System.out.println(Line1); do { if (Line1.equals("Add_Course")) { for (int i = 0; i < ToInt; i++) { Course[i] = t.next(); System.out.println(Course[i]); } t.nextLine(); Line1 = t.next(); System.out.println(Line1); } else if (Line1.equals("Add_ExamType")) { for (int i = 0; i < 6; i++) { ExamType[i] = t.next(); System.out.println(ExamType[i]); } Line1 = t.next(); System.out.println(Line1); } else if (Line1.equals("Add_Student_For_Course")) { Line1 = t.next(); System.out.println(Line1); if (Line1.equals("0")) { for (int i = 0; i < NumberOfStudents0.length; i++) { NumberOfStudents0[i] = t.next(); System.out.print(NumberOfStudents0[i]); } Line1 = t.next(); } else if (Line1.equals("1")) { for (int i = 0; i < NumberOfStudents1.length; i++) { NumberOfStudents1[i] = t.next(); System.out.print(NumberOfStudents1[i]); } Line1 = t.next(); } else if (Line1.equals("2")) { for (int i = 0; i < NumberOfStudents2.length; i++) { NumberOfStudents2[i] = t.next(); System.out.print(NumberOfStudents2[i]); } Line1 = t.next(); } else if (Line1.equals("3")) { for (int i = 0; i < NumberOfStudents3.length; i++) { NumberOfStudents3[i] = t.next(); System.out.print(NumberOfStudents3[i]); } Line1 = t.next(); System.out.println(Line1); } } else if (Line1.equals("Add_Marks")) { for (int i = 0; i < ToInt; i++) { for (int j = 0; j <n[i]; j++) { for (int k = 0; k < 6; k++) { Array3D[i][j][k] = t.nextInt(); System.out.println(Array3D[i][j][k]); } } } } } while (true); } }