Java – cannot run swing from the command line

I use the command line in windows to compile and then execute my @ L_ 502_ 1 @ procedure I've already gone http://java.sun.com/docs/books/tutorial/uiswing/start/compile.html And try to compile helloworldswing Java class It works, but when I try "Java helloworldswing", it gives me a bunch of errors and "main" Java Lang. NoClassDefFoundError: name of error: start / helloworldswing, say some abnormal lines

I try to run using java start / helloworldswing, which says NoClassDefFoundError I don't have javac errors either This is the code in the tutorial:

import javax.swing.*;        

public class HelloWorldSwing {
    /**
     * Create the GUI and show it.  For thread safety,* this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloSEOperation(JFrame.EXIT_ON_CLOSE);

        //Add the ubiquitous "Hello World" label.
        JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokelater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

Editing: using javaw

Pop up window

"Java exception occurred"

Another window

"Error: the main class could not be found. Error: a JNI error occurred. Please check your installation and try again“

Never run any Java programs with any problems. What did I miss? Is there any way to know what it is?

I was there too. Java and Run the command in the same path as class

There is no startup folder in the path of my compiler

Edit2 I tried start / helloworldswing and helloworldswing in Java

I also didn't have any errors with javac When I use javaw and Java gives me noclassdeffoundexception, I get two pop-up windows containing the messages I entered earlier, and then discuss classloaders and things like that

Edit3 I made it work by deleting "package start" What do I need to do to make it work with it?

Javaw can now also delete package lines

Solution

yes. This page has a small error:

This class uses packages, but does not use packages in run instructions

You can do two things:

a) Delete package name (delete line package start;) And run as directed

or

b) Keep packaging started; Add the - D option to javac and use the full class name

I hope it helps

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>