stjava
stjava

Reputation: 61

No output from simple program using System.out.println

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.

package hiall;
public class HiAll {

    public static void main(String[] args) {
        System.out.println("HiAll");
    }        
}

Can't get any simpler!!!

In HiAll(run) window


run: BUILD SUCCESSFUL (total time: 0 seconds)


Before I remove all java components and starting again does anyone have suggestions????

Upvotes: 3

Views: 26735

Answers (7)

David Charo Makuba
David Charo Makuba

Reputation: 51

I used to experience the same problem, I solved it using Shift + F11 and then run F6.

Upvotes: 1

vivi112
vivi112

Reputation: 41

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.

Upvotes: 4

Allister Botticchio
Allister Botticchio

Reputation: 1

Make sure you go to 'Run' - 'Set main project' - 'none'. Worked for me when i had the same problem.

Upvotes: 0

Syed Rahim
Syed Rahim

Reputation: 3

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

Upvotes: 0

Albert
Albert

Reputation: 1216

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).

Upvotes: 0

jAC
jAC

Reputation: 5324

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

If the console output is not visible, you can right click on the running process and select "Show Output"

Show Output

Upvotes: 0

Bart Hofma
Bart Hofma

Reputation: 644

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.

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);
}        
}

Upvotes: -1

Related Questions