在类中找不到Java-Main方法
我知道这个主题已经被违反了好几次,但是当我以据说在其他主题中修复的方式修复它时,我遇到了一个错误在类中找不到Java-Main方法,java,swing,main,Java,Swing,Main,我知道这个主题已经被违反了好几次,但是当我以据说在其他主题中修复的方式修复它时,我遇到了一个错误 public static class FlowAp extends JFrame{ String one = "One"; String two = "Two"; String three = "Three"; String four = "Four"; String five = "Five"; public static void main(Strin
public static class FlowAp extends JFrame{
String one = "One";
String two = "Two";
String three = "Three";
String four = "Four";
String five = "Five";
public static void main(String argv[]){
FlowAp fa=new FlowAp();
//Change from BorderLayout default
fa.getContentPane().setLayout(new FlowLayout());
fa.setSize(200,200);
fa.setVisible(true);
}
FlowAp(){
JButton one = new JButton("One");
getContentPane().add(one);
JButton two = new JButton("Two");
getContentPane().add(two);
JButton three = new JButton("Three");
getContentPane().add(three);
JButton four = new JButton("four");
getContentPane().add(four);
JButton five = new JButton("five");
getContentPane().add(five);
}
}
当我把它们放在括号中看起来应该是的地方时,另一个错误出现在flowap中。“无效的方法声明”应该是:
public static void main(String[] argv){
发布编写此文件时发生的错误
注:-类不能是静态的。应该是:
public static void main(String[] argv){
发布编写此文件时发生的错误
注:-类不能是静态的。在您的情况下,类的修饰符“static”是不允许的-删除它,它就会工作。如果你想访问你的变量,你必须使它们成为静态的,这样你就可以从main方法中引用它们。在你的例子中,你的类的修饰符“static”是不允许的-删除它,它就会起作用。如果要访问变量,必须将其设置为静态,以便从main方法引用它们。尝试删除“static”: 尝试删除“静态”: 请是基本的东西,有很多错误,我不能评论的东西,然后 源代码
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class FlowAp extends JFrame {
private static final long serialVersionUID = 1L;
private String one = "One";
private String two = "Two";
private String three = "Three";
private String four = "Four";
private String five = "Five";
public FlowAp() {
JButton oneButton = new JButton(one);
JButton twoButton = new JButton(two);
JButton threeButton = new JButton(three);
JButton fourButton = new JButton(four);
JButton fiveButton = new JButton(five);
setTitle("FlowAp");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
add(oneButton);
add(twoButton);
add(threeButton);
add(fourButton);
add(fiveButton);
setLocation(100, 100);
pack();
setVisible(true);
}
public static void main(String argv[]) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
FlowAp fa = new FlowAp();
}
});
}
}
请是基本的东西,有很多错误,我不能评论的东西,然后
源代码
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class FlowAp extends JFrame {
private static final long serialVersionUID = 1L;
private String one = "One";
private String two = "Two";
private String three = "Three";
private String four = "Four";
private String five = "Five";
public FlowAp() {
JButton oneButton = new JButton(one);
JButton twoButton = new JButton(two);
JButton threeButton = new JButton(three);
JButton fourButton = new JButton(four);
JButton fiveButton = new JButton(five);
setTitle("FlowAp");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
add(oneButton);
add(twoButton);
add(threeButton);
add(fourButton);
add(fiveButton);
setLocation(100, 100);
pack();
setVisible(true);
}
public static void main(String argv[]) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
FlowAp fa = new FlowAp();
}
});
}
}
没什么区别。
[]
s通常是您首选的方法,但C兼容的方法是有效的;没什么区别。[]
s通常是您首选的方法,但C兼容的方法是有效的;无效的方法声明到底在哪里?这是一个嵌套类吗?请提供您看到的错误的所有详细信息。您如何尝试启动该程序?问题标题似乎与正文不匹配。如果您确实有一个像样的编译器,您将得到以下错误-“FlowAp类的非法修饰符;只允许使用public、abstract和final”a)它说“FlowAp fa=new FlowAp();b)这是程序的开始。c)这是错误,我只是说其他线程中提供的修复程序由于不同的错误而无法工作。d)我使用的是NetBeans 7.0.1无效的方法声明到底在哪里?这是另一个线程中的嵌套类吗?请给出错误的所有详细信息你明白了。你是如何尝试启动这个程序的?问题的标题似乎和正文不匹配。如果你真的有一个像样的编译器,你会得到以下错误——“FlowAp类的非法修饰符;仅允许公开、抽象和最终版本”a)它在“FlowAp fa=new FlowAp()上显示错误;b) 这是节目的开始。c) 这就是错误所在,我只是简单地说,其他线程在另一个线程中提供的修复由于另一个错误而无法工作。d) 我使用的是NetBeans 7.0.1当我从类中删除静态变量时,它表示我不能在静态上下文中引用非静态变量。当我从类中删除静态变量时,它表示我不能在静态上下文中引用非静态变量。我不这么认为,但是它说如果没有静电,这是不可能的。它给出了一个单独的错误信息,关于如何在静态上下文中引用一个非静态变量。然后你应该使你的变量是静态的,而不是你的classI不这么认为,但它说没有静态变量,这是不可能的。它给出了一个单独的错误消息,关于如何在静态上下文中引用非静态变量。然后,您应该使变量是静态的,而不是类