Why IntelliJ displays error in simple java programm? - java

I run IntelliJ. Simple project and received println in red.
package test;
public class Main {
public static void main(String[] args) {
System.out.println("Console is.");
}
}
Error:
Cannot resolve method 'println'...
I have checked that in module setting JDK is. What another I should check? Thanks.

I needed to re-start IntelliJ after installing it.

Related

How to launch program in psvm?

How to launch a program in psvm with one command?
How does the application know which class to launch first?
I know that psvm should only have starting command and nothing more.
Could you explain this to me?
I mean how to create proper public static void main(String[] args) in a simple program on Maven. Should I create a class i.e. Starter with method run (with sequence actions) and in psvm write new Starter().run()?
psvm stands for public static void main as shown below:
public static void main(String[] args) {
// Your code here
}
psvm is not a standard Java terminology. You can call it as a Java slang. It is the entry point in your standalone Java application i.e. when you run an executable jar, it will execute the class having psvm. There are so much of content about it on the internet e.g. https://dzone.com/articles/executable-java-applications
The main() is the first entry point of Java application. Java Virtual Machine is told to run an application by specifying its class using the application launcher & it will look for the main() with exact syntax of public static void main(String[]).
Considering your comments you want to do something like this :
public class Starter{
public static void main(String args) {
new Starter().run();
}
public void run() {
//your logic
}
}
once you write this,
you have multiple options to run this I am mentioning a few
1) by building jar and then executing that jar using java -jar command
2) or by executing maven command once you have compiled your program using mvn compile, mvn exec:java -Dexec.mainClass="complete name of your main class i.e including package name."
a few links
http://www.vineetmanohar.com/2009/11/3-ways-to-run-java-main-from-maven/
https://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Maven_SE/Maven.html
hope this might help

Java - can't run program in Eclipse

I can't run HelloWorld in Eclipse - it shows message:
Error: Main method not found in class com.taksila.javabyexample.overview.HelloWorld, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Here is my code:
package com.taksila.javabyexample.overview;
public class HelloWorld {
public static void main(String[] args){
System.out.println("Hi Planet");
}
}
Code is correct. Try to restart IDE or just save sketch :-)
Yes, your code is definitely correct. Save it, restart the IDE, and wait to load all of its components. Then again run it!

Robocode run in eclipse

I started to code robocode with eclipse. But whenever i run the program from eclipse it gives error,
Error: Main method not found in class robo_first.robo_new, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Things i have done:
I added robocode.jar as a reference library
In run configuration
VM arguments -Xmx512M -Dsun.io.useCanonCaches=false
Working directory other - /home/sameera/robocode
project - robo_first
Main class - robo_first.robo_new
What's wrong with this? Are there anything else that I should do?
package robo_first;
import robocode.Robot;
public class robo_new extends Robot{
#Override
public void run() {
while(true){
turnGunRight(360);
ahead(100);
}
}
}
I ran above code in Robocode directly, by setting preference/development options and adding eclipse workspace/project/bin.. and it works..!!!
I'm using eclipse luna, ubuntu 14.04 and robocode 1.9.2.4
I think that the error is that you are search the main method in robo_first.robo_new
but there is no main method in that class, you must search it in robocode.Robocode the class which is inheriting.
the configuration looks like this

Error: Could not find or load main class HelloWorld (Tried many solutions on here)

Below is the code for I am using and the error I receive. This is on Mac OS X 10.9.4 in Eclipse.
CODE:
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World!");
}
}
ERROR:
Error: Could not find or load main class HelloWorld
I have attempted to delete and reimport the project, delete the bin folder, and check my classPath. It seems as though those problems have not been the issue in this case. I cannot seem to understand why I receive the error above. Any ideas?
Thanks!
Add this line before your main class:
package HelloWorld;

JDeveloper: AnnotatedNoClassDefFoundError

I have created a new Java Application in JDeveloper. That application only uses the Java application. No Swing and no ADF technologies are used.
I have created a new class with a static main method.
When I'm trying to compile the project, this error is shown:
Error: Exception thrown during compilation: oracle/classloader/util/AnnotatedNoClassDefFoundError
I'm trying to find on Google any reference of this, but each page that I see talks about ADF.
Anybody knows how to fix that issue?
Edit: the class code:
package wewe;
public class Class1 {
public Class1() {
}
public static void main(String[] args) {
Class1 class1 = new Class1();
}
}
It seems that I didn't installed correctly the JDK, and JDeveloper didn't reported. Now all works.

Categories

Resources