This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Issue with button that changes stylesheet  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to add a feature to my app that allows the user to change to a dark theme using a simple button press.
I followed a thread at https://coderanch.com/t/703106/java/Button-switch-theme - but for some reason I keep getting an error and I cant figure out why.

My main code looks like this;

Note: When I uncomment the line in the try block, my application launches with the new css (the one I want to be able to toggle too) just fine.
The code im trying to use to change scene looks like this:


Using scenebuilder I have connected the change method to a button which causes this error:

Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
... (further down in the error dialogue)
Caused by: java.lang.reflect.InvocationTargetException
... (further down in the error dialogue)
Caused by: java.lang.NullPointerException

I am very new to coding and java especially so apologies if I have worded this all poorly. Any questions please ask as I really would like this feature to work!

Thanks in advance

 
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lol I maded the example in the mentioned thread... To help you you'll need to post the full error message, you're getting a nullpointer, check on what line to find out which component is giving you the nullpointer.
Show us your fxmlfile you maded with scenebuilder, did you mark your change method with @FXML?
 
Daniel Demesmaecker
Rancher
Posts: 1170
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reasson I can't edit my post anymore, so I explain here the lol is not me laughing with the op it's just an anoying habbit of mine, sort of a catchphrase, please ignore it
 
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Daniel that we need the full error message, but I'm going to take a stab at it even before that.

Try adding after line 21:
then deleting line 4.
 
You have to be odd to be #1 - Seuss. An odd little ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!