• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null pointer

 
D Wynn
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
D Wynn
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
D Wynn
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't have this dir setup is that the problem?
 
D Wynn
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed my classpath and now it seems to be working...
 
D Wynn
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic