我在同一个文件夹中编写了几个类,这是层次结构:bookpirate/-Window.java-Navigator.java-NavEventHandler.java所有文件都有“package bookpirate;” 在一开始的时候这是我导入它们的方法:导航器类:package bookpirate;import javax.swing.*;import java.awt.*;import bookpirate.NavEventHandler;public class Navigator{ private JPanel panel; public JTextField page; public JButton pageBack; public JButton addBefore; public JButton addAfter; public JButton pageForward; public JButton removePage; public JButton undo; public JTextField getPage() { return page; } public JButton getPageBack() { return pageBack; } public JButton getAddBefore() { return addBefore; } public JButton getAddAfter() { return addAfter; } public JButton getPageForward() { return pageForward; } public JButton getRemovePage() { return removePage; } public JButton getUndo() { return undo; } public int nOfPages; public int getNOfPages() { return nOfPages; } public static void main(String[] args) { new Navigator(); } public Navigator() { setListeners(); System.out.println("Created NavEventHandler"); }这是我编译 NavEnventHandler 时得到的结果:C:\Users\...\bookpirate>javac NavEventHandler.javaNavEventHandler.java:5: error: cannot find symbolimport bookpirate.Navigator; ^ symbol: class Navigator location: package bookpirateNavEventHandler.java:9: error: cannot find symbol Navigator navigator; ^一直以来我都可以毫无错误地将它们编译在一起C:\Users\Falangrater\Desktop\Files\Programming\bookpirate>javac NavEventHandler.java Navigator.java Window.javaC:\Users\Falangrater\Desktop\Files\Programming\bookpirate>但我无法一起或单独运行它们C:\Users\Falangrater\Desktop\Files\Programming\bookpirate>java Window Navigator NavEventHandlerError: Could not find or load main class WindowC:\Users\Falangrater\Desktop\Files\Programming\bookpirate>我尝试过制作一个manifest.txt文件Main-Class: Window我无法将 .mf 添加到文件中我试图尽可能简洁
2 回答
天涯尽头无女友
TA贡献1831条经验 获得超9个赞
您不必从同一个包中导入类。
您的任何类中都没有 main 方法,因此您无法以这种方式运行它。
编辑:您只需移动到父目录并这样调用它:
java bookpirate.Navigator
或者java bookpirate/Navigator
潇湘沐
TA贡献1816条经验 获得超6个赞
这就是问题所在:
我将这些课程放在 bookpirate 包中。因此,我需要位于 bookpirate 的父文件夹中才能运行该程序:
/Programming> java bookpirate/Window
或者
/Programming> java bookpirate.Window
代替:
/bookpirate> java Window
添加回答
举报
0/150
提交
取消