This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes NullPointerException? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NullPointerException?" Watch "NullPointerException?" New topic
Author

NullPointerException?

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061


The above code produces output such as



What could cause a NullPointerException? allowedFile is a File object, and as you can see it is NOT null. Besides, if it was, the AllowedProperty constructor throws a NullPointerException with a custom message:

Any ideas why I get a NPE?


Java API Documentation
The Java Tutorial
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

The stack trace says the error occurs in the AllowedProperty constructor at line 53. Show us that whole constructor and point out which is line 53 (the first line in a file is line 1) and I will tell you exactly what the problem is.


[Jess in Action][AskingGoodQuestions]
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Thanks. I figured it out. I'm using Netbeans and it took me to the line in the setUp() method when I double clicked on the JUnit output. No wonder I was confused by that.

Layne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException?
 
Similar Threads
InputStream null when recursively transferring files. Jakarta FTP
File I/O
problem, please help
Files from a directory is not being recognized
Usage of list() with File to search files and directories