Why is my class not acceptable - java

This is my first forray into Java, and I am trying to get my head around "Hello World" using Intellij IDEA.
It's not so much the syntax I am having trouble with, more the IDE itself.
First of all, I have downloaded and installed IntelliJ IDEA, and both the 32 bit and 64 bit versions of the Java JDK. IDEA has no trouble finding my Java JDK install, and providing me with intellisense. I have created a test solution named Test, and a src directory to place my source files. My solution explorer looks like this:
My Java class is below, it compiles successfully:
public class HelloWorld {
static void main(String[] args){
System.out.println("Hello World");
}
}
I have added the Java JDK to my environmental variables on my computer, and I am able to navigate to the compiled class, and run it in command line. It runs fine.
My issue comes whenever I try and run the class from inside IDEA, for the purposes of debugging. When I click on Run, it asks me to edit my Environmental variables. In the dialogue box that appears, I select Application under Defaults, and try and select HelloWorld as my main class. I get an error telling me that HelloWorld is not acceptable, as shown below:
My question is, how do I run my Java console application inside IDEA for the purpose of debugging? What am I doing wrong?

main method should be with public modifier
public static void main(String[] args)
or even better
public static void main( final String[] args )

Dare I admit it?
I overlooked main() parameters!
main(String[] args) is of course the proper signature.
... I am pretty sure that was in Java 101.

Related

why are Static blocks not being executed in the NetBeans IDE (Java)?

I'm learning java and right now testing how static blocks work. I am trying to build and run the below code, but the static blocks are not being executed. When I compile and run the same code via the command-line (I am using command prompt(Windows 10)), the static blocks are being executed.
I am assuming this is related to some option in the IDE, but as I said I'm a still learning Java and OOP.
package statictest;
public class StaticTest {
public static void main(String args[]) {
System.out.println(Test.i);
}
}
class Test {
static int i;
static {
i = 10;
}
}
Can anyone help me out? An explanation of why this happens is also much appreciated.
PS:
When using NetBeans the output is 0
When using command-line the output is 10
You should upgrade to NetBeans 12.5.
This is a known issue in NetBeans 12.4, and has been fixed in NetBeans 12.5 (I ran a test to confirm).
Summary from the NetBeans 12.5 Features page:
NETBEANS-5832 Fixing compilation of static initializer for vanilla indexing.: https://github.com/apache/netbeans/pull/3054
The specific NetBeans JIRA ticket: Static block not compiled
i got this problem too after updating from netbeans 12.0 to 12.4, importing my old plugins fixed the problem, i think it's something related to nb-javac plugin.

can't import class src/test/java into src/main/java in eclipse

I am using gradle in eclipse.
I want to use class in src/test/java/testing inside src/main/java/program.
I tried doing :
// in program.java
public static void main(String[] args) {
final testing t = new testing();
// in testing.java
public class testing {
... some code ...
}
but the execution failed because it couldn't find symbol "class testing".
I do not see any problem in my program, so I am assuming that I did not properly set the environment up.
I've seen a post saying I have to build path but it says there's no action available.
Can someone help me set the environment up on mac?
I want to use class in src/test/java/testing inside src/main/java/program.
No, that's not how it's supposed to go. Gradle, eclipse, or for that matter any build system and any IDE will fight you.
Test code depends on main code, but main code does not depend on test code. It wouldn't work - test code is not shipped when you deploy your application.
If you want to write some tests that you run from main, put that code in src/main itself. src/test is for automated testing purposes.
If you are making a class for some data tracking that the actual test code will use, and currently this tracking class lives in src/test because you feel that is where it should go, given that it is test related - move that class to main. Anything that src/main/... uses, is by definition 'main' code.

No avilable classes when I run my program?

I am a new java coder. I am unable to run the JavaFX program and this pop up of: Browse jAVAfx APPLICATION CLASSES keeps popping up with no available classes to choose from. Please Help!!
Does your class include the main method
public static void main(String[] args)

Multiple main-methods for testing purposes in Netbeans 7.4 (project from Netbeans 7.2.1)

I recently switched from my older Netbeans version 7.2.1 to 7.4. I am working on a bigger project which uses only one main-entry point of course. However, for testing purposes I am using a second class which also contains a main-method. In my older Netbeans version I was able to Shift+F6 (Run File) and it did what it says: It runs the file because if has a valid main-method. With the never version of the IDE the program keeps telling me, that there is no main-method. This main-method is anything but special and the autocheck does not warn me either (Why wouldn't it? It is totally valid and worked in version 7.2.1).
Here is my testing class definition for the sake of completeness:
package Tests;
// various imports from surrounding project or external packages
public class TEST001 {
// variables and methods for further testing
public static void main(String[] args) throws IOException{
// [...]
}
}
Now, are there incompabilities between projects of Netbeans 7.2.1 to these of version 7.4 which might have caused this?
Or do I have to check a special option somewhere to allow the handling of multiple main-entry points? Which seems unlikely because running a file instead of the project seems to be permanent feature with its own user controls.
Or is this simply a bug?
Thank you for your suggestions.

Not using any kind of javafx application still it says extend javafx

I am using jdk 1.8 , jre 1.8 and eclipse juno.Whenever i use to run my program with eclipse it gives me this error
Error: Main method not found in class A, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
my basic program is
public class A {
public static void main(String[] args) {
System.out.println("Hello");
}
}
Then i tried to run my program from CMD on the first time it run successfully after that it also start giving me this error..Points to remember
When i create a new project i use default jre.which is jre 8.
I am not using any kind of javaFx Application.My basic program is in front of you all
I cant every time extend javafx .So i need a strong way to resolve it.
I run a program from the command prompt for the first time it run ,but when i run another program with little bit of change it did not run.
I am stuck here guys please give me a solution for that and a little bit of explanation for that will be appreciated..
Please, close your cmd prompt.
And reopen cmd prompt.
Then open your directory containing pom.xml
To build your project, Type : mvn install
Then run the java code. For eg,
java -cp target/sample-0.0.1-SNAPSHOT.jar com.maven.sample.HelloMaven
Here HelloMaven is the class name.
I had the same error. Imported java.lang.String and the error went off.
import java.lang.String;

Categories