java - NoSuchMethodException <init>() when extending javafx.scene.chart.LineChart -


i trying extend javafx.scene.chart.linechart in order add features.

i have implemented 2 constructors

public livelinechart(timeline animation, axis<number> xaxis, axis<number> yaxis)

and

public livelinechart(timeline animation, axis<number> xaxis, axis<number> yaxis, observablelist<series<number, number>> data)

my project compiles, however, when run, this:

caused by: java.lang.nosuchmethodexception: org.mypackage.livelinechart.<init>() @ java.lang.class.getconstructor0(class.java:2971) @ java.lang.class.newinstance(class.java:403) ... 20 more 

if try implement default (empty) constructor, compile error:

no suitable constructor found linechart(no arguments) constructor linechart.linechart(axis<number>,axis<number>) not applicable   (actual , formal argument lists differ in length) constructor linechart.linechart(axis<number>,axis<number>,observablelist<series<number,number>>) not applicable   (actual , formal argument lists differ in length) 

what missing able run?

linechart has no default constructor, need invoke 1 of constructors declares explicitly constructor define. looking @ constructors you've said declared, need this:

public livelinechart(timeline animation, axis<number> xaxis, axis<number> yaxis) {     super(xaxis, yaxis);     // ... }  public livelinechart(timeline animation, axis<number> xaxis, axis<number> yaxis, observablelist<series<number, number>> data) {     super(xaxis, yaxis, data) ;     // ... } 

if want able create livelinechart fxml, either need no-argument constructor, or builder class. no-argument constructor not leave mechanism initialize axes (since managed superclass , immutable, i.e. there no way set them once superclass constructor has been invoked). need define following:

public class livelinechartbuilder {     private axis<number> xaxis ;     private axis<number> yaxis ;     private timeline animation ;     private observablelist<series<number,number>> data ;      public static livelinechartbuilder create() {         return new livelinechartbuilder();     }      public livelinechartbuilder xaxis(axis<number> xaxis) {         this.xaxis = xaxis ;         return ;     }      public livelinechartbuilder yaxis(axis<number> yaxis) {         this.yaxis = yaxis ;         return ;     }      public livelinechartbuilder animation(timeline animation) {         this.animation = animation ;         return ;     }      public livelinechartbuilder data(series<number, number> data) {         this.data = data ;         return ;     }      public livelinechart build() {         // if else may not necessary, depending on how define constructors in livelinechart         if (data == null) {             return new livelinechart(animation, xaxis, yaxis);         } else {             return new livelinechart(animation, xaxis, yaxis, data);         }     } } 

this enable do

<livelinechart> <xaxis><numberaxis><!-- ... --></numberaxis></xaxis> <!-- etc --> </livelinechart> 

in fxml.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -