我做了一個示例代碼來啓動一個項目,只是重構另一個項目。「選擇不包含主要類型」 - Eclipse運行錯誤
這個重構的一個:
package com.sh.st;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingConstants;
public class Main extends JFrame implements ActionListener {
/**
*
*/
JMenuBar bar;
JMenu file, register;
JMenuItem close, search;
ImageIcon figure1= new ImageIcon("C:/Users/Victor/Downloads/Untitled.jpg");
//ImageIcon figure2= new ImageIcon("C:/Victor Rocha/carroicon.jpg");
JLabel Ibimagem1,Ibimagem2;
/**
*
*/
public Main()
{
bar= new JMenuBar();
file= new JMenu("file");
register= new JMenu("register");
register.setMnemonic(KeyEvent.VK_R);
file.setMnemonic(KeyEvent.VK_F);
close= new JMenuItem("Close");
close.addActionListener(this);
search= new JMenuItem("Search");
search.addActionListener(this);
Ibimagem1= new JLabel(figure1, JLabel.CENTER);
Ibimagem1.setVerticalTextPosition(SwingConstants.CENTER);
bar.add(file);
bar.add(register);
file.add(close);
register.add(search);
//register.add(carro);
//register.add(cliente);
//register.add(funcionario);
getContentPane().add(Ibimagem1);
setSize(800,600);
setTitle("SHST");
setJMenuBar(bar);
setDefaultCloseOperation(0);
//setIconImage(figure2.getImage());
WindowListener J=new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
};
addWindowListener(J);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==close){
System.exit(0);
}
if(e.getSource()==search){
Search s= new Search();
s.setVisible(true);
}
}
}
這是原來的一個:
package com.professordelphi.locadora;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingConstants;
public class Principal extends JFrame implements ActionListener {
JMenuBar barra;
JMenu arquivo, cadastro;
JMenuItem fechar, cliente, funcionario, carro;
ImageIcon figura1= new ImageIcon("C:/Victor Rocha/carro.jpg");
ImageIcon figura2= new ImageIcon("C:/Victor Rocha/carroicon.jpg");
JLabel Ibimagem1,Ibimagem2;
public Principal()
{
barra= new JMenuBar();
arquivo= new JMenu("Arquivo");
cadastro= new JMenu("Cadastro");
cadastro.setMnemonic(KeyEvent.VK_C);
arquivo.setMnemonic(KeyEvent.VK_A);
fechar= new JMenuItem("Fechar");
fechar.addActionListener(this);
carro= new JMenuItem("Carro");
carro.addActionListener(this);
cliente= new JMenuItem("Cliente");
cliente.addActionListener(this);
funcionario= new JMenuItem("Funcionario");
funcionario.addActionListener(this);
Ibimagem1= new JLabel(figura1, JLabel.CENTER);
Ibimagem1.setVerticalTextPosition(SwingConstants.CENTER);
barra.add(arquivo);
barra.add(cadastro);
arquivo.add(fechar);
cadastro.add(carro);
cadastro.add(cliente);
cadastro.add(funcionario);
getContentPane().add(Ibimagem1);
setSize(800,600);
setTitle("Sistema de Cadastro");
setJMenuBar(barra);
setDefaultCloseOperation(0);
setIconImage(figura2.getImage());
WindowListener J=new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
};
addWindowListener(J);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==fechar){
System.exit(0);
}
if(e.getSource()==carro){
Carro k = new Carro();
k.setVisible(true);
}
if(e.getSource()==cliente){
Cliente c = new Cliente();
c.setVisible(true);
}
if(e.getSource()==funcionario){
Funcionario f= new Funcionario();
f.setVisible(true);
}
}
}
的事情是,原來的E樓和重構不是。我從重構中收到的錯誤是「選擇不包含主類型」。我看到很多關於這個主題的帖子,但是他們都沒有解決我的問題。這是我嘗試過的一些小清單,
來源:Editor does not contain a main type
- 清理你的工作區和重建項目。
- 確保你在項目屬性 - > java build path - > source中添加你的源文件夾。
- 關閉您的項目並重新打開它。
嘗試使用Eclipse作爲Java應用程序運行,任何人都有建議我應該怎麼做?
通過阿卡什解決。 –
[錯誤:選擇不包含主要類型]的可能重複(http://stackoverflow.com/questions/16225177/error-selection-does-not-contain-a-main-type) – jww