HanSolo / medusa

A JavaFX library for Gauges
Apache License 2.0
692 stars 131 forks source link

NullPointerException when subclassing Gauges #132

Open WolfgangFahl opened 7 years ago

WolfgangFahl commented 7 years ago

there will be a NullPointerException when a gaug is subclassed e.g. with SuperGauge extends Gauge end then new SuperGauge();

WARNUNG: Stacktrace: java.lang.NullPointerException at eu.hansolo.medusa.Gauge.getUserAgentStylesheet(Gauge.java:5219)

This is due to the assumption that the gauge.css style sheet is always available in the resources. I think it would be better to throw an Exception stating this or be lenient and only issue a warning via the logs. Since the css doesn't contain anything interesting at this time the following code works for me:

@Override public String getUserAgentStylesheet() { URL u = getClass().getResource("gauge.css"); if (u!=null) return u.toExternalForm(); else return null; }

SamCarlberg commented 7 years ago

Since the resource is part of the medusa library, it'll always be available. This code should always work to get the referenced style sheet in Gauge

@Override
public String getUserAgentStylesheet() {
  return Gauge.class.getResource("gauge.css").toExternalForm();
}