eclipse 使用 System.out.println 的简单程序没有输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28072214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No output from simple program using System.out.println
提问by stjava
This has to be an easy question but can't seem to figure it out. In Netbeans and in Eclipse I have successful builds but no output. I'm thinking that there is something wrong with my JDK (possibly??) I can't post a screen shot:( so I'll include the code.
这必须是一个简单的问题,但似乎无法弄清楚。在 Netbeans 和 Eclipse 中,我成功构建但没有输出。我在想我的 JDK 有问题(可能是??)我无法发布屏幕截图 :( 所以我将包含代码。
package hiall;
public class HiAll {
public static void main(String[] args) {
System.out.println("HiAll");
}
}
Can't get any simpler!!!
不能再简单了!!!
In HiAll(run) window
在 HiAll(run) 窗口中
run: BUILD SUCCESSFUL (total time: 0 seconds)
运行:BUILD SUCCESSFUL(总时间:0 秒)
Before I remove all java components and starting again does anyone have suggestions????
在我删除所有 Java 组件并重新开始之前,有人有什么建议吗????
回答by jAC
In Netbeans there should be a so called "Output" Window in the down-right corner of your screen, which should show the console output (System.out.println("");
).
Logically this does only occur, when you run the .jar-file by pressing "Run" (F6) (which is different from compiling or building [F11]).
在 Netbeans 中,屏幕右下角应该有一个所谓的“输出”窗口,它应该显示控制台输出 ( System.out.println("");
)。
从逻辑上讲,这只会在您通过按“运行”(F6)(这与编译或构建 [F11] 不同)运行 .jar 文件时发生。
If the console output is not visible, you can right click on the running process and select "Show Output"
如果控制台输出不可见,您可以右键单击正在运行的进程并选择“显示输出”
回答by vivi112
I had this exact problem in NetBeans (11.1) and the solution for me was to Clean+Build the project (Shift + F11). After that, running the project with F6 printed the expected output.
我在 NetBeans (11.1) 中遇到了这个确切的问题,我的解决方案是 Clean+Build 项目 (Shift + F11)。之后,使用 F6 运行项目打印预期的输出。
回答by Bart Hofma
It outputs in your IDE's console, you won't see anything outside Eclipse Look for the 'console' tab. In Eclipse it's in the bottom part of the screen (when you have default settings) . I don't know about NetBeans but should be similar.
它在 IDE 的控制台中输出,在 Eclipse 之外您将看不到任何内容 查找“控制台”选项卡。在 Eclipse 中,它位于屏幕的底部(当您有默认设置时)。我不知道 NetBeans,但应该是类似的。
If you expect a screen to pop-up and show you this text you could do this:
如果您希望弹出一个屏幕并向您显示此文本,您可以这样做:
package hiall;
public class HiAll {
public static void main(String[] args) {
JFrame f=new JFrame();
JLabel label=new JLabel("HiAll");
f.add(label, BorderLayout.CENTER);
f.setVisible(true);
f.setSize(400,400);
}
}
回答by Gherbi Hicham
Maybe you're not running the code and instead just compiling it , press Ctrl+F11 in order to execute on Eclipse .
也许您没有运行代码而只是编译它,按 Ctrl+F11 以便在 Eclipse 上执行。
回答by Albert
Before remove anything, I'd try:
在删除任何东西之前,我会尝试:
- Compile and run from command line using same JDK/JRE that is used in Eclipse/NetBeans. Does it print anything?
- As others suggest, make sure you are running the right class. Right-click on Java file: Run As->Java Application. Note that CTRL+F11, at least in Eclipse, runs last lauched, not the Windows that has the focus. So, it could not work if last program launched is not the class you are trying to run.
- Make sure you can see 'Console View'. If not, Menu->Window->Show View->Console View (in Eclipse).
- 使用 Eclipse/NetBeans 中使用的相同 JDK/JRE 从命令行编译和运行。它打印任何东西吗?
- 正如其他人建议的那样,请确保您正在运行正确的课程。右键单击 Java 文件:Run As->Java Application。请注意,至少在 Eclipse 中,CTRL+F11 运行最后启动,而不是具有焦点的 Windows。因此,如果上次启动的程序不是您要运行的类,则它无法工作。
- 确保您可以看到“控制台视图”。如果没有,菜单->窗口->显示视图->控制台视图(在Eclipse中)。
回答by Syed Rahim
In the Projects panel on Netbeans (which should be the top left panel), right click on the class you're running and then press "run file". You can open the output window by opening Windows -> Output
在 Netbeans 的 Projects 面板(应该是左上角的面板)中,右键单击您正在运行的类,然后按“运行文件”。您可以通过打开 Windows -> Output 打开输出窗口
回答by Allister Botticchio
Make sure you go to 'Run' - 'Set main project' - 'none'. Worked for me when i had the same problem.
确保您转到“运行”-“设置主项目”-“无”。当我遇到同样的问题时对我来说有效。