Hi,
ich habe ein merkwürdiges Phänomen:
Ich habe eine GUI-Applikation, die ich innerhalb von Eclipse auch prima als Java-Application ausführen kann.
Wenn ich das dann jedoch von der Kommandozeile außerhalb von Eclipse aufrufen möchte,
bekomme ich immer folgende Exception:
Die GUI ist mit dem VE erstellt.
Die GUI-Klasse verwendet JPanel, das allerdings anschließend in einem JFrame hinzugefügt wird.
Muss ich da noch irgendwas beachten? Ich poste hier mal den vom VE erzeugten Code:
Ok, der ist nicht schön, aber aufräumen kann ich erst, wenn das Ding funktionert.
Hier noch eine Main-Classzum Aufruf:
Habt ihr einen Hinweis für mich?
Danke,
Thomas
ich habe ein merkwürdiges Phänomen:
Ich habe eine GUI-Applikation, die ich innerhalb von Eclipse auch prima als Java-Application ausführen kann.
Wenn ich das dann jedoch von der Kommandozeile außerhalb von Eclipse aufrufen möchte,
bekomme ich immer folgende Exception:
Code:
Exception in thread "main" java.lang.NoClassDefFoundError: TagRlf (wrong name: main/TagRlf)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Die GUI ist mit dem VE erstellt.
Die GUI-Klasse verwendet JPanel, das allerdings anschließend in einem JFrame hinzugefügt wird.
Muss ich da noch irgendwas beachten? Ich poste hier mal den vom VE erzeugten Code:
Code:
package main;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
public class GenGUI extends JPanel {
private static final long serialVersionUID = 1L;
public static JTextField jTF_FileIn = null;
private JButton jBtn_BrowseFileIn = null;
public static JTextField jTF_GraphicIn = null;
private JButton jBtn_BrowseGraphicIn = null;
public static JTextField jTF_FileOut = null;
private JButton jBtn_BrowseFileOut = null;
private JLabel jLabel_FileIn = null;
private JLabel jLabel_GraphicIn = null;
private JLabel jLabel = null;
private JLabel jLabel_Target = null;
private JPanel jPanel_Target = null;
public static JComboBox jComboBox_Target = null;
public static JButton jButton_Start = null;
private String[] targetValues = { "edit", "print", "winhelp", "htmlhelp"};
private JScrollPane jScrollPane = null;
public static JTextArea jTextArea_Output = null;
public static JFrame mainWindow;
/**
* This is the main constructor
*/
public GenGUI() {
super();
mainWindow = new JFrame("Test");
mainWindow.setResizable(false);
mainWindow.setSize(790, 472);
mainWindow.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
mainWindow.add(this);
mainWindow.setJMenuBar(this.createMenuBar());
this.setVisible(true);
this.requestFocus(true);
initialize();
mainWindow.setVisible(true);
}
/**
* This method initializes this
*
* @return void
*/
public void initialize() {
GridBagConstraints gridBagConstraints12 = new GridBagConstraints();
gridBagConstraints12.fill = GridBagConstraints.BOTH;
gridBagConstraints12.gridy = 13;
gridBagConstraints12.weightx = 1.0;
gridBagConstraints12.weighty = 1.0;
gridBagConstraints12.gridwidth = 5;
gridBagConstraints12.insets = new Insets(5, 5, 5, 5);
gridBagConstraints12.ipadx = 0;
gridBagConstraints12.ipady = 0;
gridBagConstraints12.gridx = 1;
GridBagConstraints gridBagConstraints27 = new GridBagConstraints();
gridBagConstraints27.gridx = 2;
gridBagConstraints27.insets = new Insets(0, 5, 5, 5);
gridBagConstraints27.anchor = GridBagConstraints.CENTER;
gridBagConstraints27.gridy = 14;
GridBagConstraints gridBagConstraints22 = new GridBagConstraints();
gridBagConstraints22.gridx = 1;
gridBagConstraints22.anchor = GridBagConstraints.WEST;
gridBagConstraints22.insets = new Insets(0, 5, 0, 0);
gridBagConstraints22.gridy = 8;
GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
gridBagConstraints16.gridx = 1;
gridBagConstraints16.gridy = 7;
GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
gridBagConstraints15.gridx = 1;
gridBagConstraints15.anchor = GridBagConstraints.WEST;
gridBagConstraints15.insets = new Insets(5, 5, 0, 0);
gridBagConstraints15.gridy = 7;
jLabel_Target = new JLabel();
jLabel_Target.setText("Target");
GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
gridBagConstraints8.gridx = 1;
gridBagConstraints8.anchor = GridBagConstraints.WEST;
gridBagConstraints8.insets = new Insets(10, 5, 0, 0);
gridBagConstraints8.gridy = 5;
jLabel = new JLabel();
jLabel.setText("Output folder");
GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
gridBagConstraints7.gridx = 1;
gridBagConstraints7.anchor = GridBagConstraints.WEST;
gridBagConstraints7.insets = new Insets(10, 5, 0, 0);
gridBagConstraints7.gridy = 3;
jLabel_GraphicIn = new JLabel();
jLabel_GraphicIn.setText("Graphic folder");
GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
gridBagConstraints6.gridx = 1;
gridBagConstraints6.anchor = GridBagConstraints.WEST;
gridBagConstraints6.insets = new Insets(0, 5, 0, 0);
gridBagConstraints6.gridy = 1;
jLabel_FileIn = new JLabel();
jLabel_FileIn.setText("Input file");
GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
gridBagConstraints4.gridx = 3;
gridBagConstraints4.insets = new Insets(0, 0, 0, 5);
gridBagConstraints4.gridy = 6;
GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
gridBagConstraints3.fill = GridBagConstraints.BOTH;
gridBagConstraints3.gridy = 6;
gridBagConstraints3.weightx = 1.0;
gridBagConstraints3.gridwidth = 2;
gridBagConstraints3.insets = new Insets(0, 5, 0, 5);
gridBagConstraints3.gridx = 1;
GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
gridBagConstraints2.gridx = 3;
gridBagConstraints2.insets = new Insets(0, 0, 0, 5);
gridBagConstraints2.gridy = 4;
GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
gridBagConstraints11.fill = GridBagConstraints.BOTH;
gridBagConstraints11.gridy = 4;
gridBagConstraints11.weightx = 1.0;
gridBagConstraints11.gridwidth = 2;
gridBagConstraints11.insets = new Insets(0, 5, 0, 5);
gridBagConstraints11.gridx = 1;
GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
gridBagConstraints1.gridx = 3;
gridBagConstraints1.insets = new Insets(0, 0, 0, 5);
gridBagConstraints1.gridy = 2;
GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.gridy = 2;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.insets = new Insets(0, 5, 0, 5);
gridBagConstraints.gridx = 0;
this.setSize(600, 400);
this.setLayout(new GridBagLayout());
this.setVisible(true);
this.add(getJTF_FileIn(), gridBagConstraints);
this.add(getJBtn_BrowseFileIn(), gridBagConstraints1);
this.add(getJTF_GraphicIn(), gridBagConstraints11);
this.add(getJBtn_BrowseGraphicIn(), gridBagConstraints2);
this.add(getJTF_FileOut(), gridBagConstraints3);
this.add(getJBtn_BrowseFileOut(), gridBagConstraints4);
this.add(jLabel_FileIn, gridBagConstraints6);
this.add(jLabel_GraphicIn, gridBagConstraints7);
this.add(jLabel, gridBagConstraints8);
this.add(jLabel_Target, gridBagConstraints15);
this.add(getJPanel_Target(), gridBagConstraints16);
this.add(getJComboBox_Target(), gridBagConstraints22);
this.add(getJButton_Start(), gridBagConstraints27);
this.add(getJScrollPane(), gridBagConstraints12);
}
/**
* This method initializes jTF_FileIn
*
* @return javax.swing.JTextField
*/
private JTextField getJTF_FileIn() {
if (jTF_FileIn == null) {
jTF_FileIn = new JTextField();
}
return jTF_FileIn;
}
/**
* This method initializes jBtn_BrowseFileIn
*
* @return javax.swing.JButton
*/
private JButton getJBtn_BrowseFileIn() {
if (jBtn_BrowseFileIn == null) {
jBtn_BrowseFileIn = new JButton("Browse");
jBtn_BrowseFileIn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setCurrentDirectory(new File(jTF_FileIn.getText()));
int state = fc.showOpenDialog(null);
if (state == JFileChooser.APPROVE_OPTION){
jTF_FileIn.setText(fc.getSelectedFile().getPath());
}
}
});
}
return jBtn_BrowseFileIn;
}
/**
* This method initializes jTF_GraphicIn
*
* @return javax.swing.JTextField
*/
private JTextField getJTF_GraphicIn() {
if (jTF_GraphicIn == null) {
jTF_GraphicIn = new JTextField();
}
return jTF_GraphicIn;
}
/**
* This method initializes jBtn_BrowseGraphicIn
*
* @return javax.swing.JButton
*/
private JButton getJBtn_BrowseGraphicIn() {
if (jBtn_BrowseGraphicIn == null) {
jBtn_BrowseGraphicIn = new JButton("Browse");
jBtn_BrowseGraphicIn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setCurrentDirectory(new File(jTF_GraphicIn.getText()));
int state = fc.showOpenDialog(null);
if (state == JFileChooser.APPROVE_OPTION){
jTF_GraphicIn.setText(fc.getSelectedFile().getPath());
}
}
});
}
return jBtn_BrowseGraphicIn;
}
/**
* This method initializes jTF_FileOut
*
* @return javax.swing.JTextField
*/
private JTextField getJTF_FileOut() {
if (jTF_FileOut == null) {
jTF_FileOut = new JTextField();
}
return jTF_FileOut;
}
/**
* This method initializes jBtn_BrowseFileOut
*
* @return javax.swing.JButton
*/
private JButton getJBtn_BrowseFileOut() {
if (jBtn_BrowseFileOut == null) {
jBtn_BrowseFileOut = new JButton("Browse");
jBtn_BrowseFileOut.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setCurrentDirectory(new File(jTF_FileOut.getText()));
int state = fc.showOpenDialog(null);
if (state == JFileChooser.APPROVE_OPTION){
jTF_FileOut.setText(fc.getSelectedFile().getPath());
}
}
});
}
return jBtn_BrowseFileOut;
}
/**
* This method initializes jPanel_Target
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel_Target() {
if (jPanel_Target == null) {
jPanel_Target = new JPanel();
jPanel_Target.setLayout(new GridBagLayout());
}
return jPanel_Target;
}
/**
* This method initializes jComboBox_Target
*
* @return javax.swing.JComboBox
*/
private JComboBox getJComboBox_Target() {
if (jComboBox_Target == null) {
jComboBox_Target = new JComboBox(targetValues);
jComboBox_Target.setSelectedIndex(1);
}
return jComboBox_Target;
}
/**
* This method initializes jButton_Start
*
* @return javax.swing.JButton
*/
private JButton getJButton_Start() {
if (jButton_Start == null) {
jButton_Start = new JButton();
jButton_Start.setText("Start Generator");
jButton_Start.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
jTextArea_Output.setText("");
//now starting the generator in a separate thread
Generator g = new Generator();
new Thread(g).start();
}
});
}
return jButton_Start;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setViewportView(getJTextArea_Output());
}
return jScrollPane;
}
/**
* This method initializes jTextArea_Output
*
* @return javax.swing.JTextArea
*/
private JTextArea getJTextArea_Output() {
if (jTextArea_Output == null) {
jTextArea_Output = new JTextArea();
}
return jTextArea_Output;
}
public JMenuBar createMenuBar() {
JMenuBar menuBar;
JMenu menu;
JMenuItem menuItem;
menuBar = new JMenuBar();
//Build the first menu.
menu = new JMenu("Settings");
menu.setMnemonic(KeyEvent.VK_S);
menuBar.add(menu);
//JMenuItems group
menuItem = new JMenuItem("Load", KeyEvent.VK_L);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_1, ActionEvent.ALT_MASK));
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Settings.loadSettings();
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Save", KeyEvent.VK_S);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_2, ActionEvent.ALT_MASK));
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Settings.saveSettings();
}
});
menu.add(menuItem);
//Build second menu in the menu bar.
menu = new JMenu("Help");
menu.setMnemonic(KeyEvent.VK_H);
menuBar.add(menu);
//JMenuItems group
menuItem = new JMenuItem("Help", KeyEvent.VK_H);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_3, ActionEvent.ALT_MASK));
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Help.openHelp();
}
});
menu.add(menuItem);
menuItem = new JMenuItem("About", KeyEvent.VK_A);
menuItem.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_4, ActionEvent.ALT_MASK));
menuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
Help.openAbout();
}
});
menu.add(menuItem);
return menuBar;
}
}
Ok, der ist nicht schön, aber aufräumen kann ich erst, wenn das Ding funktionert.
Hier noch eine Main-Classzum Aufruf:
Code:
package main;
public class TagRlf {
public static void main(String[] args) {
GenGUI gui = new GenGUI();
gui.setVisible(true);
GenGUI.jTextArea_Output.setText("Test.\n\n");
}
}
Habt ihr einen Hinweis für mich?
Danke,
Thomas