我无法通过命令提示符运行基本程序,但我可以通过IDE运行它

问题描述 投票:-2回答:1

我无法通过命令提示符(Windows 10)运行任何java程序,但我可以通过我正在使用的IDE(IntelliJ)运行它们。我目前正在使用一个非常基本的JFrame程序对其进行测试,我将在下面提供。我能够使用javac命令编译.java文件,但每当我尝试使用java命令运行它时,我都会收到错误:“错误:无法找到或加载主类JavaTestProgram.java引起:java。 lang.ClassNotFoundException:JavaTestProgram.java“

我试图在系统设置下修复PATH变量,并尝试使用不同的IDE和文本编辑器。

import java.awt.FlowLayout;

import javax.swing.*;

public class JavaTestProgram {

    public static void main(String s[]) {

        JFrame frame = new JFrame("JFrame Example");

        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout());

        JLabel label = new JLabel("This is a label!");

        JButton button = new JButton();
        button.setText("Press me");

        panel.add(label);
        panel.add(button);

        frame.add(panel);
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

    }

}
java command-line ide
1个回答
1
投票

基于提供的错误消息,它看起来像是因为您正在尝试使用JavaTestProgram.java的类名。班级名称应该只是JavaTestProgram

© www.soinside.com 2019 - 2024. All rights reserved.