Java eclipse some error?
我有一些代码的问题错误是
Error: Main method is not static in class ilkframe.ilkframe, please
define the main method as:
public static void main(String[] args)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | //My Code Is and its want me to write more and pls what should I do ? package ilkframe; //Kodlar //IlkFrame import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.JButton; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public static void main(String[] args) { class ilkframe extends JFrame { private JPanel contentPane; private JTextField txtIsim; private JTextField txtSoyisim; public void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { ilkframe frame = new ilkframe(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } ///////////////////////////////////////////////////////// public ilkframe() { setTitle("Ilk Frame"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 314, 205); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); // JLabel lblNewLabel = new JLabel("Isim :"); lblNewLabel.setBounds(51, 41, 46, 14); contentPane.add(lblNewLabel); JLabel lblNewLabel_1 = new JLabel("Soyisim :"); lblNewLabel_1.setBounds(51, 78, 46, 14); contentPane.add(lblNewLabel_1); txtIsim = new JTextField(); txtIsim.setBounds(107, 38, 117, 20); contentPane.add(txtIsim); txtIsim.setColumns(10); // txtSoyisim = new JTextField(); txtSoyisim.setBounds(107, 75, 117, 20); contentPane.add(txtSoyisim); txtSoyisim.setColumns(10); // //Button Olayi JButton btnGonder = new JButton("Gonder"); btnGonder.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent arg0) { //ikinci frame i ?agiriyoruz. ikinciframe ikifrm=new ikinciframe(); //Isim ve soyismi ikinci framedeki metoda gonderiyoruz. //her ne kadar bir JFrame olarak kullansakta bunun bir sinif oldugunu //unutmamak lazim. ikifrm.gelenlerVeriler(txtIsim.getText(), txtSoyisim.getText()); //Ikinci Jframe gorunur hale getiriyor. ikifrm.setVisible(true); } }); btnGonder.setBounds(135, 106, 89, 23); contentPane.add(btnGonder); } } //ikinci Frame class ikinciframe extends JFrame { private JPanel contentPane; //TextField i global olarak tanimlamak ?nemli ?ünkü her yerden //erisebiliriz buna. private JTextField txtGelenler; public void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { ikinciframe frame = new ikinciframe(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public ikinciframe() { setTitle("Ikinci Frame"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 120); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JLabel lblNewLabel = new JLabel("Gelen Veriler :"); lblNewLabel.setBounds(10, 30, 91, 14); lblNewLabel.setSize(100,11); contentPane.add(lblNewLabel); txtGelenler = new JTextField(); txtGelenler.setBounds(111, 27, 269, 20); contentPane.add(txtGelenler); txtGelenler.setColumns(10); } public void gelenlerVeriler(String isim,String soyisim){ //Gelen verileri txtGelenlere Aktariyoruz. txtGelenler.setText(isim+""+soyisim); } } } //This is the problem hlp me pls the problem is Error: Main method is not static //in class ilkframe.ilkframe, please define the main method as: // public static void main(String[] args) //help me pls as fast as you can ? |
您已经错误地定义了两个类中正确放置的主方法:
1 |
合资公司告诉你:
1 2 | Main method is not static in class ilkframe.ilkframe, please define the main method as: public static void main(String[] args) |
此外,还定义了类外部的主方法
1 2 3 4 5 |
这根本不应该编译。删除那个声明…方法需要在类中
仅供参考:这不是Eclipse错误,我希望出现编译错误,然后出现运行时错误。但全部来自Java,而不是Eclipse。