java - NetBeans bug showing on example code in book "Pro JavaFX 8: A Definitive Guide" initializing objects in FXML file -
in chapter 3 of "pro javafx 8: definitive guide building desktop, mobile, , embedded java clients", example illustrating how specify objects directly in fxml file generates errors in netbeans 8.0.2 (i downloaded code book's site , other examples tried far worked).
this fxml snippet:
<discount> <utilities fx:constant="ten_pct"/> </discount>
is supposed initialize field discount
constant ten_pct
defined in utilities.java:
package projavafx.fxmlbasicfeatures; import java.util.arraylist; import java.util.list; public class utilities { public static final double ten_pct = 0.1d; public static final double twenty_pct = 0.2d; public static final double thirty_pct = 0.3d; public static list<integer> createlist() { return new arraylist<>(); } }
the tool tip error "constant 'ten_pct' not defined utilities."
another error in same example appears @ point:
<profits> <hashmap q1="1000" q2="1100" q3="1200" a4="1300"/> </profits>
with error "class 'java.util.hashmap' not support property 'q1' ", analogous errors other keys.
what reason these errors, , how can fixed?
here's files (besides utilities.java above):
fxmlbasicfeatures.fxml:
<?import javafx.scene.paint.color?> <?import projavafx.fxmlbasicfeatures.fxmlbasicfeaturesbean?> <?import projavafx.fxmlbasicfeatures.utilities?> <?import java.lang.double?> <?import java.lang.integer?> <?import java.lang.long?> <?import java.util.hashmap?> <?import java.lang.string?> <fxmlbasicfeaturesbean name="john smith" flag="true" count="12345" xmlns:fx="http://javafx.com/fxml/1"> <address>12345 main st.</address> <foreground>#ff8800</foreground> <background> <color red="0.0" green="1.0" blue="0.5"/> </background> <price> <double fx:value="3.1415926"/> </price> <discount> <utilities fx:constant="ten_pct"/> </discount> <sizes> <utilities fx:factory="createlist"> <integer fx:value="1"/> <integer fx:value="2"/> <integer fx:value="3"/> </utilities> </sizes> <profits> <hashmap q1="1000" q2="1100" q3="1200" a4="1300"/> </profits> <fx:define> <long fx:id="inv" fx:value="9765625"/> </fx:define> <inventory> <fx:reference source="inv"/> </inventory> <products> <string fx:value="widget"/> <string fx:value="gadget"/> <string fx:value="models"/> </products> <abbreviations ca="california" ny="new york" fl="florida" mo="missouri"/> </fxmlbasicfeaturesbean>
fxmlbasicfeaturesbean.java:
package projavafx.fxmlbasicfeatures; import javafx.scene.paint.color; import java.util.arraylist; import java.util.hashmap; import java.util.list; import java.util.map; public class fxmlbasicfeaturesbean { private string name; private string address; private boolean flag; private int count; private color foreground; private color background; private double price; private double discount; private list<integer> sizes; private map<string, double> profits; private long inventory; private list<string> products = new arraylist<string>(); private map<string, string> abbreviations = new hashmap<>(); public string getname() { return name; } public void setname(string name) { this.name = name; } public string getaddress() { return address; } public void setaddress(string address) { this.address = address; } public boolean isflag() { return flag; } public void setflag(boolean flag) { this.flag = flag; } public int getcount() { return count; } public void setcount(int count) { this.count = count; } public color getforeground() { return foreground; } public void setforeground(color foreground) { this.foreground = foreground; } public color getbackground() { return background; } public void setbackground(color background) { this.background = background; } public double getprice() { return price; } public void setprice(double price) { this.price = price; } public double getdiscount() { return discount; } public void setdiscount(double discount) { this.discount = discount; } public list<integer> getsizes() { return sizes; } public void setsizes(list<integer> sizes) { this.sizes = sizes; } public map<string, double> getprofits() { return profits; } public void setprofits(map<string, double> profits) { this.profits = profits; } public long getinventory() { return inventory; } public void setinventory(long inventory) { this.inventory = inventory; } public list<string> getproducts() { return products; } public map<string, string> getabbreviations() { return abbreviations; } @override public string tostring() { return "fxmlbasicfeaturesbean{" + "name='" + name + '\'' + ",\n\taddress='" + address + '\'' + ",\n\tflag=" + flag + ",\n\tcount=" + count + ",\n\tforeground=" + foreground + ",\n\tbackground=" + background + ",\n\tprice=" + price + ",\n\tdiscount=" + discount + ",\n\tsizes=" + sizes + ",\n\tprofits=" + profits + ",\n\tinventory=" + inventory + ",\n\tproducts=" + products + ",\n\tabbreviations=" + abbreviations + '}'; } }
fxmlbasicfeaturesmain.java:
package projavafx.fxmlbasicfeatures; import javafx.fxml.fxmlloader; import java.io.ioexception; public class fxmlbasicfeaturesmain { public static void main(string[] args) throws ioexception { fxmlbasicfeaturesbean bean = fxmlloader.load( fxmlbasicfeaturesmain.class.getresource( "/projavafx/fxmlbasicfeatures/fxmlbasicfeatures.fxml") ); system.out.println("bean = " + bean); } }
both of errors see in netbeans editor due bugs in netbeans itself. issue within netbeans editor, fxmlloader
happily process these statements noticed yourself, when running sample application.
the first error happens because netbeans doesn't seem allow constant fields of type differs enclosing class' type. following snippet work, because constant double.positive_infinity double itself:
<discount> <double fx:constant="positive_infinity"/> </discount>
the second error happens because special use case of maps not supported in netbeans editor.
i've submitted bug reports these 2 cases in netbeans bugzilla.
constant 'ten_pct
not defined utilities`: https://netbeans.org/bugzilla/show_bug.cgi?id=252416
class 'java.util.hashmap' not support property 'q1'
: https://netbeans.org/bugzilla/show_bug.cgi?id=252417
Comments
Post a Comment