简体   繁体   English

即使声明了类(字体)和方法(字体)也找不到符号?

[英]Cannot find symbol even though class (Font) & method (font) are declared?

I'm writing my codes and couldn't compile even though the class (Font) is already imported via import javafx.scene.text.*; 我正在编写代码,即使已经通过import javafx.scene.text.*;了类(Font),也无法编译import javafx.scene.text.*; and I know that method font is included within Font. 而且我知道font中包含方法字体。

Here's my code: 这是我的代码:

package helloworld;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.GridPane;
import javafx.scene.text.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import javafx.geometry.*;
import javafx.scene.paint.Color;

public class HelloWorld extends Application {
    public static void main(String[] args) {
        launch(args);
    }


    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("PDF Export");

        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(25, 25, 25, 25));

        Text scenetitle = new Text("PDF Password");
        scenetitle.setFont(Font.font("Tahoma",FontWeight.NORMAL,20));
        grid.add(scenetitle, 0, 0, 2, 1);
...

}

And when I compile, here's the error I got 当我编译时,这是我得到的错误

PS D:\Documents\javafx\helloworld> javac HelloWorld.java
HelloWorld.java:58: error: cannot find symbol
                scenetitle.setFont(Font.font("Tahoma",FontWeight.NORMAL,20));
                                       ^
  symbol:   method font(String,FontWeight,int)
  location: class Font
1 error

Would anyone kindly tell me what I'm missing? 有人可以告诉我我所缺少的吗? Because I can't seem to figure out what I might have done wrong. 因为我似乎无法弄清楚我做错了什么。

I find that a lot with JavaFX I have to clean my project after any changes to the things related to JavaFX. 我发现在使用JavaFX进行很多工作之后,必须对与JavaFX相关的内容进行任何更改后再清理项目。

(I run NetBeans but the error could be in other IDEs as well). (我运行NetBeans,但该错误也可能发生在其他IDE中)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java:即使该方法稍后在类中声明,也无法找到该方法的符号。 其余的代码正在寻找一个类。 - Java: Cannot find a method's symbol even though that method is declared later in the class. The remaining code is looking for a class. 即使它们在同一个 package 中也找不到符号 - Cannot Find Symbol even though they are in the same package “找不到符号:方法”但声明了方法 - “cannot find symbol: method” but the method is declared 当我返回一个数组时,即使我已经声明了数组,我也会收到“找不到符号”错误 - When I return an array, I'm getting a "cannot find symbol" error even though I have declared the array 即使我导入了 java.lang.*,deleteCharAt() 方法的“找不到符号”错误 - "cannot find symbol" error for deleteCharAt() method even though I imported java.lang.* 测试 class 中未声明的方法,即使它在原始 class 中声明 - Undeclared method in test class even though it's declared in original class 即使定义了类和参数,Java也找不到符号错误? - Java cannot find symbol errors even though class and parameters has been defined? 即使在同一类中声明了对象也无法找到对象 - Unable to find object even though it is declared in same class 找不到符号符号:方法位置:类 - cannot find symbol symbol: method location: class “找不到符号:方法”但方法是在 Storm.java 中定义和声明的 - "Cannot find symbol: Method" but method is defined and declared in Storm.java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM