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;
Related
I made a java application using javaFx on Eclipse IDE.
I am using JavaSE-11 compiler and the javafx-sdk-11 version.
It works when I run it from Eclipse, but now i'm trying to make a runnable .jar of the application.
When I double click on the .jar, nothing happens. I tried installing, uninstalling and reinstalling Java ...
Here are the issues I'm having when I try to launch it with [java -jar filename.jar] command :
Extracting the required libraries into generated JAR
java : Error : JavaFX runtime components are missing,
and are required to run this application
Packaging the required libraries into generated JAR
java : Graphics Device intialization failed for : d3d, sw
Error initializing QuantumRenderer : no suitable pipeline found
Don't hesitate to ask me more details, I'm not very good at this but I'm trying my best.
Thanks
I had same problem few days back. I just made another class that doesn't extend Application, and has its own main. Then just launched the application from that class like so:
public class Fakemain {
public static void main(String[] args) {
game.main(args); //this is the class that extends Application
}
}
Let me know if this worked for you.
I'm just getting started with Java. This is my program:
package javaapplication1;
public class JavaApplication1
{
public static void main(String[] args)
{
System.out.println("Hello ");
}
}
If I remove the first line package javaapplication1, the code won't run. I did the same thing in class but it was working.
Can someone explain why does this happen?
If you are working with terminal along with package statement, save your code as JavaApplication1.java
and then compile your current code with below syntax.
javac -d . JavaApplication1.java
( -d . indicates create directory in current location because we are using package statement).
then for execution of your code you need to change directory with
cd javaapplication1
then execute your code with
java JavaApplication1
It will execute fine.
But if you are working without package statement seen will differ, you need to compile code normally with
javac JavaApplication1.java
then execute code with
java JavaApplication1
You will not get an error.
Note: But If you are using any IDE nothing to worry about. IDE will take care of package statement.
error: Could not find or load main class: this error appears at runtime if JVM is unable to find main class.
You need to change the directory as I mentioned above, then it might work fine.
This has to do with the way your IDE sets up your project.
When you start learning a new language, it's always a good idea to skip the IDE until it actually becomes useful. I suggest you copy your program to a basic text editor, remove the package line, save it as JavaApplication1.java and manually compile and run with javac JavaApplication1.java and java JavaApplication1.
I'm trying to execute carel programs based on CSA106a Stanford class videos available on YouTube.
I've downloaded the jar and related files, imported the whole project into Neon Eclipse and am trying to run.
While clicking "run", I get the error:
Error: Could not find or load main class (default package).CheckerboardKarel
Note: other programs that I have created in Neon from scratch are working fine (not imported ones). Please help.
I've attached the screenshots as well.
I can't tell for sure, but I think there might not be a "main" function in what you downloaded. In order for a java program to run the class you are running needs to have a main function. it should look like:
public static void main(String[] args){
...
}
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.
a few years back in college I wrote TONS of simple little java programs... I haven't used them in a while and I would like to go back and revist them. I believe I used Netbeans as my IDE (but i also could have used Eclipse... cant remember)..
anyways long story short.... I cant remember how to compile them and I cant open these as projects in any of my IDEs....
I've tried using javac and then java to run a few in the command line, however one specifically will not run and gives me this error:
Exception in thread "main" java.lang.NoSuchMethodError: main
I know this is because I don't have a public static void main method in this program. I can't remember why I don't.... but here's in theory how it should work.... I have 3 program files:
race.java
bicyclePanel.java
controlPanel.java
race extends JApplet and has a method public void init().... which creates an instance of controlPanel class.... controlPanel class creates an instance of bicyclePanel and so on and so forth....
my question is.. am I supposed to have a main method? How can I rebuild this into an IDE and run? It's been so many years I cant remember all the in's & outs of java :(
Yes, you are supposed to have the main method if you plan on running it as a standalone Java application. In Eclipse you can use the Applet runner to run your applets directy as well. It's Run As -> Java Applet.
Fire up NetBeans or Eclipse and Import the Projects with existing sources. It will do most of the stuff. You may have to adjust the broken references.