For some reason I do not have any ability to run the below code in IntelliJ. Neither the Run button or any key shortcuts will work.
I'm relatively new to this but I believe the below code should work, I have declared the public Elevator class and variables in another class file in the project.
public static void main(String args []){
Elevator myElevator = new Elevator();
myElevator.openDoor();
myElevator.closeDoor();
myElevator.goDown();
myElevator.goUp();
myElevator.goUp();
myElevator.goUp();
}
Ive even had a colleague look at this and he's stumped. Is this simply some issue with the way my project is set up?
Apologies if I'm just being thick and can't see it.
Related
I am coding java on vscode. I have source folder:
>...
>lib
>>src
exam1.java
exam1.class
>>Month10
app1.class
app1.java
With:
exam1.java
public class exam1 {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
app1.java
package Month10;
public class app1 {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
I want to ask about why I need to use package Month10 in here. And another, exam1.java run well(both run code and run java), but in app1.java, I only can "run java", can't "run code" (Ctrl+Alt+N in vs code), it exists error Could not find or load main class app1, I think because the command package? (I saved file before running), can anyone help me, thanks.
The Code Runner extension sometimes has problems running code under multiple levels of folders. For a better coding experience, please use the official extension to run the code.
Tips:
Run Code is provided by Code Runner
Run Java and Debug Java are provided by the official extension
You can ask questions about the Code Runne here.
reload VS Code window or F1 ->Clean the java language server workspace. try this could help
Out of nowhere when I run my application no GUI pops up only says BUILD SUCCESSFUL (total time: 1 second) in the console, don't know why it happened or if anyone has had this before? Tried restarting netbeans etc ill post my code below incase its that. And it was working at one point.
pastebin(dot)com/XvD30sCP code is here
public static void main(String args[]) {
global_crime gc = new global_crime();
gc.setVisible(true);
}
Add this... it will work now..
Eclipse give error when I try to compile and run to JAVA codes. The error is
"The selection cannot be launched, and there are no recent launches".
How to fix this issue ??
your code is wrong. you need a main method to launch your program
package main;
public class main {
public static void main (String[] args) {
System.out.println("Test");
}
}
Note: The name of the class always has to be the name of the file, and typically java classes start with an uppercase letter
I think you should run main first and describe your problem in more detail if you still have a problem.
Q: When I try to run my project by clicking the green "Play" button, I get an error of, "The Selection cannot be launched, and there are no recent launches."
A: See previous question. You must run your project's "Main" class at least once by using the right-click method described above, before the "Play button" to run a project will work.
http://courses.cs.washington.edu/courses/cse143/15wi/eclipse_tutorial/faq.shtml
Trying to learn Java again and I cannot remember how I figured this out the first time around.
I have 3 classes; a GameLauncher, GuessGame, and Player. GameLauncher has my main method.
They are all packaged as chap02, I cannot remember if that is important to me yet.
I am compiling like this: javac GameLauncher.java GuessGame.java Player.java
running like this: java GameLauncher
I am getting this error: Could not find or load main class GameLauncher.
I know this is a ridiculous issue, but I have always had trouble with this kind of stuff. The actual programming and writing code I can pick up just fine, but dealing with these damn compilers always gets me. Any help would be appreciated. Thanks
package chap02;
public class GameLauncher {
public static void main (String[] args) {
GuessGame game = new GuessGame();
game.startGame();
}
}
Edit: The issue isn't with the actual code, the issue is with how I am compiling it.
When running the program, you have to run it form the correct directory. Remember, that you used packages, so you have the following package-structure
src
chap02
GameLauncher.java
GuessGame.java
Player.java
after compilation, you will find the corresponding .class-files in the chap02-folder. To start the game, you have run the following command from the src-directory:
java chap02.GameLauncher
Since you specified a package in the source code, you have to use the full qualified name, including the package, to which the class belongs.
EDIT as vefthym mentioned, you have to compile the code in the same way, running
javac chap02/GameLauncher.java
from the source-directory.
EDIT 2
"src" is the directory, where your src lies. I, for example, have my Code unter X:\JDK-Projects[Project-name]\src. You have to specify the full absolute path to the src-Directory or the relative path form the directory you are currently in.
This is my first post on the forum, hope all of you guys are well.
I've got a issue using JiST/SWANS, the ad hoc simulator in java within eclipse.
I managed to load the API, (as an external JAR ofcourse) but Im basically having a problem integrating the runtime of JiST within eclipse.
After running the hello world im usually getting a stackoverflowerror exception, since it may need modifications within the runtime.
import jist.runtime.JistAPI;
public class hello implements JistAPI.Entity {
/**
* #param args
*/
public static void main(String[] args) {
System.out.println("simulation start");
hello t = new hello();
t.myEvent();
}
public void myEvent()
{
JistAPI.sleep(1);
myEvent();
System.out.println("hello world, t=" + JistAPI.getTime());
}
}
the website is: http://jist.ece.cornell.edu/index.html
Thank you in advance!
Actually you need to run Main.java within jist.runtime. But before rigth click Main.java, properties, Run/Debug settings, New,Arguments and type your class name (plain name no .java needed) in Progam arguments. This will tell the jist interface to translate your code using the rewriter and run it.
Examples:
To run hello.java type "hello"
To run aodvsim.java type: "jist.swans.Main driver.aodvsim"
If there are arguments needed type them after the clas name like: "jist.swans.Main driver.aodvsim -n 25 -f 2000x2000 -a grid:5x5 -t 10,600,60"
Wilmer Arellano
How well does SWANS work? Given that the documentation and code date back to 2005, I am not sure if this is the best platform to use.