Java won't run in VSCode - imports not functioning - java

Ok, so I followed the guide on vscode website to the T, and I'm stuck where it says the debugger will create the launch.json for me. There is no launch.json.
Here's the guide for your ref - https://code.visualstudio.com/docs/java/java-tutorial
When I run the code it tells me that none of the packages/methods are defined. Specifically that anything outside of that single file is undefined. any imports don't work at all; Although all the packages/methods are there and included in the program.
main.java:2: error: package exceptions does not exist
import exceptions.myException;
Even the pre-built program I cloned from github doesn't work.
I've installed the java extensions pack which includes Language Support for Java(TM) by Red Hat and Debugger for Java.
I have JDK installed and the path is defined in my environment variables as JAVA_HOME - C:\Program Files (x86)\Java\jdk1.8.0_161.
I've also installed maven and checked to make the version checked out through the CMD prompt.
I've watched around 10 yt vids and they all say the same thing.
if anyone has a decent guide on how to set this up or can personally walk me through the process I would greatly appreciate it.

Related

Can't get Java to work in Visual Studio Code

I've been trying to install java on vs code for a couple hours now and I can't seem to get it to work. I've already downloaded all the extensions necessary and I've downloaded the coding pack from https://code.visualstudio.com/docs/languages/java for windows (I'm on windows 11). According to multiple tutorials, this is all I should have to do, but when I make a test.java file, the "run java" does nothing and "run code" gives me an error.
and this is the output when I click that run button in the top right:
Does anybody have any suggestions? the coding pack was supposed to come with a jdk, its working for everybody else so I'm not sure what the issue is.
It seems like you don't have correctly installed java sdk on your system.
Try to check java sdk installation with following commands:
java --version
javac --version
In case you don't see reasonable output, try to install java sdk,
go to the Java Downloads section of the Oracle website, and download the Installer from there.
Are you sure you are following the documentation? It looks like you didn't download the official Java extension pack, but used Code Runner to run the code.
Please download the Java extension package and use Run Java or Run to run the code.
Getting Started with Java in VS Code.

JavaFX setup is not working, because of environment variables possibly

I will be using JavaFX on a project. I am no expert but I did install it once with no major issue or problem.
But I switched to a new computer and after trying to install it doesn't build; at first I got the message that
JavaFX runtime components were missing then got the java.lang.module.FindException: Module javafx.controls not found
and I did check other posts that had the same error as the mentioned above but got no solution to the problem and now the message is
Unrecognized option: --module-path Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.
(Please note that I'm using VS Code and no build tools, I am referencing the libraries to use JavaFX)
Path to JavaFX
launch.json configured
JRE path
Environment variables
And I'm really confused with the JRE, SDK and JDK, I installed the SDK using VS Code but I don't know if my environment variables are configured as they should be...
Thanks in advance for the help, since I'm no expert I don't know if this information is enough, I hope it is :)
My suggestion is to use JavaFX of vscode to build the project instead of JavaFX SDK.
I think the main problem is still caused by the environmental settings.
If you must use the JavaFX SDK, put it in a location without spaces, or quote the path when using it. And please read the document in detail.

Visual Studio Code Java Setup Assitance

I recently installed visual studio on my Ubuntu Linux machine. I also installed Java on my Ubuntu system but I keep getting "Classpath is incomplete" warning" anytime I run my a java code as well as Java implicit super constructor not defined whenever I run my code. I would like an easy to understand solution on how to fix this particular problem.
Edit:
I tried this exact same code on my Mac and it doesn't give me the "Java implicit super Constructor not defined" warning.
If you getting that error message you can try below steps:-
1) Open Command Palette (Ctrl+Shift+P) and typing the command Java: Configure Java Runtime.
2) Scroll down to install JDK, Choose the version(I chose latest one), download it install it (during installation you get the option to add the path to java_home variable choose it) ,after clicking finish on set up click reload on vs code.
This has already been answered at Visual Studio Code - Java Classpath is incomplete. Only syntax errors will be reported
Visual studio code does not support java right out of the box without a maven or eclipse project defining the classpath. Best solution in my opinion is to use eclipse or intellij or any other java IDE instead of VSCode.
The constructor error you're getting is because your class isn't starting with a capital letters. Classes should always start with a capital letter.
Java naming conventions: http://www.oracle.com/technetwork/java/codeconventions-135099.html

Runnable Jar made in Eclipse, Doesn't work on pc's without JDK installed

I've made a little snake game and exported it into a runnable JAR file through Eclipse.
It works perfect in machines with JDK installed (with regards to the environment variables and all that.)
But "normal" people don't have that installed, only the JRE that can be found here: http://java.com/en/download/index.jsp
This is insufficient to execute the JAR apparently. I've tried numerous approaches:
packeging libraries in Jar
Extracting libraries in Jar
Build with java 1.7
building with java 1.8
checked the build path to make sure the libraries is included.
At best I get a "Java Exception occured" on the other PC (the one with JDK installed).
I've then tried to run the JAR on my own machine through cmd with the command...
java -jar fileName.jar
...in the hope that I would get an error log, but nope, it just runs the JAR like there's no problem.
Any ideas on how to make the JAR run on a machine with JRE installed?
Thanks in advance
Check packr
Packages your JAR, assets and a JVM for distribution on Windows, Linux
and Mac OS X
Appareantly, build for jre7 fixed the problem, why it can't run jre8, i don't know..
The JDK includes a tools.jar (among many others) which are omitted from the JRE. In your project expand the JRE System Libraries and make sure none of the libraries are coming from the a JDK.
Also adding some example text of the exact error you're seeing would really help us know what's going on. Stating "Java Exception occurred" is the equivalent of telling a doctor you don't feel well.
For what it's worth it's not a good idea to use classes from the JDK in your code as it has stricter licensing than the JRE.

issue with java and environment variables on windows

I've got a curious problem. After installing java jdk 6u25 I tested the installation by typing java in the command prompt. Everything worked fine , the console displayed the usage options as expected. This was about 3 weeks ago - I recently reinstalled windows 7 on my machine- Now I would like to get started with the play framework and followed a tutorial. I got a new application with play new but couldn't use play run because of this:
play! 1.2.3, http://www.playframework.org
Ctrl+C to stop
Could not execute the java executable, please make sure the JAVA_HOME environment variable is set properly .
The funny thing is that typing java in the console still displays usage options and neither eclipse or netbeans complained about a missing jdk. Nevertheless I checked my environment variables and was surprised to find:
No reference to java at all.
Seriously I got no idea how the console, eclipse and netbeans found my java. As a first countermeasure I once again reinstalled java hoping that the installer might set the path correctly. It didn't. Now I would like your advise: Should I just create the JAVA_HOME variable ? If I do, will further versions of the jdk override the variable to point to the new version or will I have to change the variable manually everytime? What about eclipse and netbeans. I would guess that they have been downloaded with their "own" jdk. If I want to update java on my machine, will it update their versions, too ?
Update:
I set the environment variable manually and restarted the pc. Now everything works fine but I would like to know what symbolic link is. Could you just give me a link in a comment or explain briefly ?
Eclipse and netbeans use a different way of finding your java installation than command line tools likes play, ant, maven, gradle etc.
IDEs may search your registry, guess default locations, or even have the JRE prepackaged with the installation.
Command-line tools usually rely on JAVA_HOME variable. And you have to set that manually.
Should I just create the JAVA_HOME variable ?
There are several tools that use that environment variable, so I'd recommend creating it.
If I do, will further versions of the jdk override the variable to point to the new version or will I have to change the variable manually everytime?
If you install your new Java version into the same folder (or if you create symbolic links), then no.
What about eclipse and netbeans. I would guess that they have been downloaded with their "own" jdk. If I want to update java on my machine, will it update their versions, too ?
That depends on whether the JDK is prebundled and how the configuration is done. I can't speak for Netbeans but in Eclipse, you could add this to your eclipse.ini:
-vm
C:/Java/jre/bin
Note that this is an example path to the bin folder. If you don't add versions there or use symbolic links (see above) then you'd not have to update the path when installing a new version.
It is possible that you have a (older?) java.exe in C:\windows or other common directory.
Make sure that the java you get on the command line is the one you think it is:
java -version

Categories

Resources