I'm using Intellij IDEA Community 2020.1
When I try to run this super-simple example code:
public class testConsole {
public static void main(String[] args) {
System.out.println("Wish I could see this important info");
System.exit(1);
}
}
I see the important message flash up in the console for a split-second, then the screen immediately switches to an error about the non-zero exit code:
Execution failed for task ':testConsole.main()'.
> Process 'command 'C:/Program Files (x86)/Java/jdk1.7.0_71/bin/java.exe'' finished with non-zero exit value 1
Is there any way to switch back to the console so I can see what was printed to sysout?
I discovered if I click on the top red exclamation point, I can then scroll up to see the sysout.
I think what was happening is to do with having a warning in another part of the project. When I moved that code into a new project that has no compilation errors, the sysout remains even when there's a non-zero exit code.
I met some interesting question on which I was not able to find an answer. Does anybody know how to pass hieroglyphs as an argument to the main method from command line?
Below there is some pseudo code which will help to test suggested solution:
public class Test {
public static void main(String args[]) {
if ("香港政府".equals(args[0])) {
System.out.println("Match");
}
}
}
So question is how to call Test.class with an argument so the application prints Match to the console? args[0] can be transformed before passing to the if statement.
Thanks in advance.
After some additional research I was able kinda figured it out. So guys who commented on question were very near to the answer.
Encoding which I tried to find was 936. But it doesn't mean that you will be able to run chcp 936 if you OS locale is other than chinese. Once you will try to run it on other locale than chinese:
chcp 936
You will get following error:
Invalide code page
For making it working you have to change region. FOllowing steps will be needed:
Start - COntrol panel
Select "Region and Language"
Select "Administrative" and click "Change system locale..."
Select "Chinese (Simplified, PRC)" and reboot laptop
After restart when you will run chcp you will see following output Active code page: 936. Now you are ready to execute command line with hieroglyphs.
I'm still new to Java and so I'm not understanding where the termination error is coming from. The System.out.println in the main is not being printed out and it says:
< terminated, exit value: 0> C:\Program Files\Java\jre1.8.0_71\bin\javaw.exe (Jan 27, 2016, 1:22:17 PM)
Here is the main of my code.
public class BrainCenter {
public static void main(String[] args) {
System.out.println("Welcome to the Stock Center!");
System.out.println("Realtime Reports within the stock market");
System.out.println("");
Market mk = new Market(6000);
mk.printMarket();
System.out.println("Individual status listed below");
System.out.println("");
Buyers bu = new Buyers();
bu.buildRandomPortfolio(mk);
}
}
The first three lines are not being outputted and I'm not sure why. It appears as the rest of the code loads but then disappear and said to be terminated at the end. I'm using Eclipse IDE.
Any help would be greatly appreciated. Thank you in advance!
Try to use java.exe instead of javaw.exe. The first will wait until the program completes. It will also put all output the program generates directly in console. The last should be used when the program runs with its own GUI or simply in background. It will not wait until the program completes.
See Difference between java.exe and javaw.exe.
you can fix this problem by setting path variable in Environment. In my system I have copied path of bin as "C:\Program Files\Java\jdk1.8.0_25\bin" and saved.
I am trying to run this project called "hello user". I am new to Java, so wrote a simple program that takes your name, and displays "Hello ". while Running it, I get the following error:
run:
Error: Could not find or load main class hello.world.HelloWorld
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
But when I run file HelloWorld.java, it does it fine
I am doing this on Netbeans IDE 7.2
Rather than the coding error, it could be related to IDE. Since the "Run File" runs okay, but 'Run Project" does not, I believe you have something to set up in IDE itself. Right click the project, and select "Set is as Main", now run the project. I am just giving it a guess, may not help you. But it worth a shot.If it does not help, please paste your code too.
Your class needs a public static void main(String[] args) function. And moreover I suspect that the error could be in the package.
If you want your class in <main_package>.<sub_package>, The directory structure is
- main_package
- sub_package
-HelloWorld.java
And be sure to write your class like this.
package main_package.sub_package;
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hello " + args[o]);
}
}
This is all due to the naming convention in Java
You need to run the .class file containing the public static void main(String[] args) method..
Here, your HelloWorld.java file might contain a class with main() method.. So, you can run it..
This is because, execution of any Java program starts with the invocation of main().. JVM needs an entry point to your code.. Which is main().. If it doesn't find one.. It will not run..
So, make sure, whatever class file you are running, it should have main() method..
UPDATE :- And for the starting point, may be you can skip using packages.. Just go with plain Java class without packages..
This message can also appear in Eclipse (Juno 4.2.2 in my case) and I have found two potential causes for it.
In my cases:
1. a DTD was in error. I deleted the file and that solved the issue*.
2. having cleaned the project, an external Jar that I had built externally had been deleted as could be seen from Properties -> Java Build Path -> Libraries.*
*Having solved either of the above issues, it was necessary to restart Eclipse
if you are using intellij idea then just rebuilding (clean and build) project might solve your problem . because intellij might be still trying to load the old classes which are not there or changed
Make sure you call looks like below:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello user");
}
}
To run a Java class in stand alone mode, public static void main(String[] args) is the entry method, which is must.
I am using eclipse for long time and this never happened but I have this really simple program . And it doesnt display anything . what can be the reason ?
public class ReportGenerator {
public static void main(String[] args){
System.out.println("STARTING");
}
}
try Window -> Show View -> Console if the console is not visible
If you are doing javac ReportGenerator.java, it is just building a .class file. You need to run java ReportGenerator to see the program working and therefore printing on the terminal in your case.
Too many opened consoles in Eclipse?
Here is the reference: http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fviews%2Fconsole%2Fref-open_action.htm
Click the grey X until all of them are closed.