gpt4 book ai didi

java - Java错误: String cannot be resolved into a type(S is uppercase)

转载 作者:行者123 更新时间:2023-12-02 11:14:11 24 4
gpt4 key购买 nike

在这段代码中,我收到了错误(来自eclipse)“无法将字符串解析为类型”:

package tilegame.display;

import javax.swing.JFrame;

public class Display {
private JFrame frame;
private String title;
private int width, height;
public Display() {
public Display(String title, int width, int height){
this.title = title;
this.width = width;
this.height = height;
createDisplay();
}
}
public void createDisplay() {
frame = new JFrame(title);
frame.setSize(width, height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

我搜索了一下,但是“String”是大写的,并且我有来自Eclipse的Java库。

最佳答案

不要嵌套构造函数。尝试这个:

package tilegame.display;

import javax.swing.JFrame;

public class Display {
private JFrame frame;
private String title;
private int width, height;
public Display() {

}
public Display(String title, int width, int height){
this.title = title;
this.width = width;
this.height = height;
createDisplay();
}
public void createDisplay() {
frame = new JFrame(title);
frame.setSize(width, height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

关于java - Java错误: String cannot be resolved into a type(S is uppercase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46139612/

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