aspose file tools*
The moose likes I/O and Streams and the fly likes Null pointer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Null pointer" Watch "Null pointer" New topic
Author

Null pointer

D Wynn
Ranch Hand

Joined: May 03, 2004
Posts: 38
Hello,
I have a problem, I've been asking to correct some existing code which is having a problem displaying a pdf file...I'm trying to understand what is going on here but because I've only been coding in Java for a little while it's nothing making sense. Even and after reading the java docs I still don't get it. And why is templateInputStream null. Here is the code...


fullTemplatePath = this.getTemplateName(fullTemplatePath, curChild.getAttributeValue("state"));


fullTemplatePath=com/test/newBizFormTemplates/together/TN/GeneralAppPage1.pdf


InputStream templateInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fullTemplatePath);

Could someone please point in the direction where I can get a better understanding of whats going on here and why? I really want to learn Java as its all that I'm doing now on my job. Please help! Also any addition info on really learning Java would also be helpful. I just got Head First Java and Head First OOA&D...any other feedback on books to read etc. would help.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Both getContextClassLoader() and getResourceAsStream() can return null; the first if the context class loader isn't set (quite common!) and the second if there's no such resource -- i.e., if the path isn't correct. Is there an existing file GeneralAppPage1.pdf in a directory com/test/newBizFormTemplates/together/TN/ someplace on the classpath?


[Jess in Action][AskingGoodQuestions]
D Wynn
Ranch Hand

Joined: May 03, 2004
Posts: 38
How can I tell in Eclipse? Again, I'm new to Java and to make matters worst or better...I've only used vi, so eclipse is new to me as well.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Step 1 is to separate the statement:

That way, you can see from the stack trace if the class loader is null - the second line will be at the top of the stack trace.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
D Wynn
Ranch Hand

Joined: May 03, 2004
Posts: 38
Going through the debug...this is what classLoader is when I step over the first statement...

org.eclipse.core.runtime.CoreException: Unable to access archive C:\dev\RAD7\plugins\org.eclipse.jdt.source_3.0.0\src\org.junit_3.8.1\junitsrc.zip
D Wynn
Ranch Hand

Joined: May 03, 2004
Posts: 38
I don't have this dir setup is that the problem?
D Wynn
Ranch Hand

Joined: May 03, 2004
Posts: 38
I changed my classpath and now it seems to be working...
D Wynn
Ranch Hand

Joined: May 03, 2004
Posts: 38
Instead of C:\dev\RAD7 my classpath was setup like this.. C:\dev\RAD7Shared so I changed it to that and it seems to be working. One question if my made the change on my workstation how will this solve the problem our testing group was having with this same problem. I'm lost on this one please direct me on how changing my classpath worked.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Null pointer