0

This is an employee-management-system. Which has some cool functions(methods)like searching for an employee by the index position, registering users by index position etc. Now at its last functionality, I face a big issue and don't know where the problem could be.

Will share the method and the error message but could also share the whole code if someone is interested, but keep in mind I am sure that it lays somewhere hidden in the method:

public static void sucheL(String[] nN) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Geben Sie den Text ein: ");
        String nn = sc.nextLine();
        boolean gefunden = false;
        // check for all the entries in nN
        // if the entry starts with the entered String or
        for (int i = 0; i < nN.length; i++)
            if (nN[i].startsWith(nn)) {
                System.out.println("Der Name " + nN[i] + " beginnt mit " + nn);
                gefunden = true;
                // break;
                // if it contains the entered String
            } else if (nN[i].contains(nn)) {
                System.out.println("Der Name " + nN[i] + " enthält " + nn);
                gefunden = true;
                // break;
            }
        if (!gefunden) {
            System.err.println("Es wurde kein Name gefunden, der mit dem eingegebenen Text beginnt oder ihn beinhaltet");
        } else {
            System.out.println("Es wurde mindestens ein Name gefunden, der mit dem eingegebenen Text beginnt oder ihn beinhaltet");
        }
    }

Error message:

Exception in thread "main" java.lang.NullPointerException
    at PersonalVerwaltung.sucheL(PersonalVerwaltung.java:148)
    at PersonalVerwaltung.main(PersonalVerwaltung.java:54)
Jwan
  • 51
  • 6
  • 1
    Where is line 148? – WJS Apr 28 '20 at 20:43
  • As the first statement in your method, put `System.out.println(Arrays.toString(nN));` – WJS Apr 28 '20 at 20:44
  • It's genuinely amazing how it is possible to understand German without any knowledge but based on the context and a bit of guesswork! – Chris Apr 28 '20 at 20:52
  • I took a look at it before asking this question and no it unfortunately doesn't, because I feel this is another case, although it is the same error. – Jwan Apr 29 '20 at 07:15
  • @WJS it's this line > `if (nN[i].startsWith(nn)) ` – Jwan Apr 29 '20 at 16:20
  • The I would say it's either nN[i] or nn that's null. That is why I suggested you print out the String array. To visually see if there are any nulls – WJS Apr 29 '20 at 16:22
  • Well yes there are a lot of nulls in the array, but is this not normal cuz i have still nothing in the array? Where it says juju, is my input from right now `[null, null, juju, null, null,` – Jwan Apr 29 '20 at 16:25
  • 1
    You asked why you got an NPE. That is why. The reason that there are nulls is impossible for anyone to determine without understanding your code logic You simply need to debug it. – WJS Apr 29 '20 at 16:28
  • 1
    Thanks man, your answer now let me know that the issue lays someone else. @WJS – Jwan Apr 29 '20 at 19:59

0 Answers0