File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Java 8 .load() fails but Java 7 Works Fine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java 8 .load() fails but Java 7 Works Fine" Watch "Java 8 .load() fails but Java 7 Works Fine" New topic
Author

Java 8 .load() fails but Java 7 Works Fine

peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
Hi Guys...

i had a program that has been working fine since finishing it but just upgraded to java 8 and now it wont run and errors with a null pointer...

the place that causes all the trouble is below..



that line returns a null exception in java 8 but fine in 7



any idea?

many thanks...
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3487
    
  13
peter hammond wrote:that line returns a null exception in java 8 but fine in 7


If that line is throwing a NullPointerException then myLoader must be null, so the problem is actually on the previous line.
My first guess would be that getClass().getResource(resource) is not returning the required resource, so you may want to check the resource still exists where you thought it was.


Joanne
peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
Hi Thanks for a prompt reply..

the resource still shows there but it works fine on 10 java 7 machines but fails on the Java 8 machines, if i set the JDK to test program back to 7.40 it works fine....

something has changed in the Java 8




the stack trace is this... if it was resourse issue it would say destication not known?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38478
    
  23
Put a line to print out myLoader in the middle of that code snippet.
Have you been through the API for getResoiurce() in Java7 and Java8?
peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
i had a look but i can see anything obvious i was getting confused as not totally sure what i need to be looking at and what to compare..



output is

Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3487
    
  13
So it's not a NullPointerException, it's a javafx.fxml.LoadException.
Might be worth asking a moderator to link this post to the JavaFX forum.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38478
    
  23
Joanne Neal wrote: . . . Might be worth asking a moderator to link this post to the JavaFX forum.
Somebody has done that already, Joanne. Thank you for the suggestion.
peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
have been having a play and reading up on the errors and after i remove all the static components on the initialize the GUI does display, so im guessing i need to remove all static components from the @FXML and use a getter to get the components from other classes when i want to use them..

seems a bit extreme as it works on everything up to java 8
John Damien Smith
Ranch Hand

Joined: Jan 26, 2012
Posts: 142
    
    9
> have been having a play and reading up on the errors and after i remove all the static components

That's a known incompatibility between FXML in Java 7 and Java 8.

http://stackoverflow.com/questions/23105433/javafx-8-compatibility-issues-fxml-static-fields

> im guessing i need to remove all static components from the @FXML and use a getter to get the components from other classes when i want to use them

Yes.

IMO that's a good idea in any case.
Having a lot of static members all over your application is usually a pretty bad design anyway:
http://stackoverflow.com/questions/7026507/why-are-static-variables-considered-evil.

You can take a look at this StackOverflow answer for some alternate methods to achieve what you are trying to do:
http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml

> seems a bit extreme as it works on everything up to java 8

Yeah, I don't think the introduced incompatibility was truly intentional.
peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
wow thanks for the link John Damien Smith thats exactly what i need...

thanks guys will get on and redesign my project..

when i started out as a greenhorn when i started my project 2 years ago it has grown when i learnt more and more about how to structure projects, so its been a long term coming to recode a lot of it...

very grateful for the support..

many thanks..
peter hammond
Ranch Hand

Joined: Apr 20, 2011
Posts: 41
that was hard work 3 hours of changing code today and still a few more classes left to do..

well at-least i learnt how to do it properly now...

 
jQuery in Action, 2nd edition
 
subject: Java 8 .load() fails but Java 7 Works Fine