gpt4 book ai didi

java - 为什么 javac 编译器找不到 javafx.collections 但我正在使用它?

转载 作者:行者123 更新时间:2023-12-01 19:28:24 26 4
gpt4 key购买 nike

这是我的代码的相关部分

package ReadWriteDisplayTriangles;

import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.collections;

class TrianglePane extends Pane{

private RecordTable recordTable;

//other code

public void setToRecordTable() {
ObservableList<Node> list = getChildren();
int size = list.size();
recordTable.setNewRecordArray(size);
for(int i = 0; i < size; i++) {
if(Debug.isDebug5() == true) {System.out.println("Observable list " + i + " is " + list.get(i)); }
}
}
}

这是 javac -verbose 的输出

[search path for class files: C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\resources.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\rt.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\sunrsasign.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\jsse.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\jce.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\charsets.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\jfr.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\classes,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\access-bridge-32.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\cldrdata.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\dnsns.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jaccess.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\localedata.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\nashorn.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\sunec.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\sunjce_provider.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\sunmscapi.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\sunpkcs11.jar,C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\zipfs.jar,.]
[loading ZipFileIndexFileObject[C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar(javafx/scene/layout/Pane.class)]]
[loading ZipFileIndexFileObject[C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar(javafx/scene/paint/Color.class)]]
[loading ZipFileIndexFileObject[C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar(javafx/scene/shape/Polygon.class)]]
[loading ZipFileIndexFileObject[C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar(javafx/event/ActionEvent.class)]]
[loading ZipFileIndexFileObject[C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar(javafx/event/EventHandler.class)]]
TrianglePane.java:9: error: cannot find symbol
import javafx.collections;
^
symbol: class collections
location: package javafx
[loading ZipFileIndexFileObject[C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar(javafx/scene/layout/Region.class)]]
[loading ZipFileIndexFileObject[C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar(javafx/scene/Parent.class)]]
[loading ZipFileIndexFileObject[C:\Program Files (x86)\Java\jdk1.8.0_241\jre\lib\ext\jfxrt.jar(javafx/scene/Node.class)]]

我有几个问题。

  1. TrianglePane 扩展了 Pane。在 javafx.scene.layout.Pane 的文档中,它列出为 getChildren() 方法,该方法返回 ObservableList。既然它扩展的类有一个返回可观察列表的方法,为什么我必须导入 javafx.collections?
  2. getChildren().add(...) 在同一代码的其他部分工作,因此它必须能够以某种方式访问​​可观察列表,对吧?
  3. 为什么 javafx.collections 没有导入?我可以从 javafx 导入其他所有内容。
  4. 我该如何修复我的编译器、库或其他内容,以便能够利用此可观察列表的引用?

我使用的是jdk1.8.0_241

感谢您的任何意见,我是编码新手,玩得很开心。

最佳答案

要导入完整的包,需要使用*:

import javafx.collections.*;

或者,按名称导入类:

import javafx.collections.ObservableList;

关于java - 为什么 javac 编译器找不到 javafx.collections 但我正在使用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60664137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com