'How can i throw an illegalargumentexception? I keep getting NullPointerException, but i am supposed to be executing vowels with an error on null

The code should throw an IllegalArgumentException when executing vowels, but I keep getting a NullPointerException. What am I doing wrong? What is the correct way to throw an IllegalArgumentException?

public class VowelChecker {
    public static void main(String args[]) {
        System.out.println(isAllVowels("A test string."));
    }

    public static boolean isAllVowels(String str){
        String temp = str.toLowerCase();
        for(int i = 0; i < temp.length(); i++){
            char x = temp.charAt(i);
            if (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u')  {
                throw new IllegalArgumentException("characters must be vowels");
            } else {
                return false;
            }
        }
        return true;
    }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source