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
Related
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
I have a robocode.jar to extend,and then i want to run it from shell.
I can't run it from shell because i get the following error
error: Main method not found in class tema1, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
I've searched ,but no answer helped me.
This is my script:
#!/bin/bash
javac -cp robocode.jar: tema1.java
java -cp robocode.jar: tema1
My class it's extendig their class and I have to make it work in the game.
http://robocode.sourceforge.net/
When I run it from Eclipse it's working fine,the game starts,but from shell it's not working
Can someone help me figure out what i have to do to make it work from shell and not only from ide?
Like the error says, you'll have to define a static method main in your class tema1 as follows:
public static void main(String[] args) {
/* your main program */
}
The main method is where your program execution starts.
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!
SOLVED, Program was in location with national symbol in it's path.
I just started studying java, but every program i try to start (even example ones from my course) shows an error.
Error: Could not find or load main class "Any class name of program I try start"
C:\Users\Mine\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
edit:
example of code, but happens to any code.
public class Hello {
static void hello(){
System.out.println("Hello, World!");
}
public static void main(String[] args) {
hello();
}
}
This error means that when Netbeans is invoking the JVM, the JVM cannot find the class file for the class Netbeans is telling it to run. When you create a project in Netbeans, the classpath will be configured for you by the IDE, so you shouldn't normally see this error unless you have deleted the auto-generated main class and made a new one from scratch in the wrong place.
So the first thing to do is check what class Netbeans is using as the main class:
Right-click on the project name in the Projects tab and click on "Properties"
Then click on "Run" and check the name of the class in "Main Class":
Note in my example the class is called "tests.Test". This means the class Test in the package "tests". In your question, your class "Hello" doesn't have a package declaration at the top (although you may have chosen not to copy this). If you have no package (and you really should be using packages, even for trivial programs like "Hello, World!", just to get used to doing so, if nothing else), the "Main Class" entry should just be the class name.
So you need to either move your class into the package specified in this parameter, or change this parameter to match the fully qualified name of your main class
Error: Could not find or load main class "Any class name of program I try start"
C:\Users\Mine\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
You are attempting to run a class called Any class name of program I try start, however the name of your class is Hello.
I don't know how Netbeans does things, but I would first try compiling and running the program without netbeans.
javac Hello.java
java Hello
If that works then open up the run settings in netbeans and make sure that it is doing the same thing.
Just make a new main class or just re-type public static void main(String[] args) { } and that's it.
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.