Why isn't my code running in VisuaStudioCode? - java

I downloaded VS code and tried to run a basic java code in it. I have already installed JDK in my system, set the environment variables too and also downloaded the red hat extension for java. The code runs smoothly in cmd prompt.
But when i run the code in VS it says "File not found in the output and "Hello.java is a non project file" .
The same problem is arising in C program too.
What should i do to resolve this?
[Image] [1]: https://i.stack.imgur.com/hh8o0.jpg

In some cases, launch.json cwd configuration is causing these errors. Could you please also share launch.json file.
This thread might help too.

File not found in Output.
That's because you're running tempCodeRunnerfile.java but hello.java was opened. Also you use the extension Code Runner, so the result will be shown in Output.
After cleaning java workspace, open tempCodeRunnerfile.java and click the triangle button(Run Code) to try again.
It's recommended that using the integrated Terminal to run the code instead of Code Runner.
Hello.java is a non project file.
This couldn't be called as an error but just a warning. Press Ctrl+Shift+P to open Command Platte and choose Java: Create Java Project. Coding in project, this warning won't be shown.
Gif tutorial and more information please refer to Creating a source code file.

Related

Symbol Not Found - Sublime Text 3 -

I have created a simple program that runs in Eclipse when I click on run. The class containing the main method ("HelloMain.java") instantiates a second class, "Hello.java" This works fine in Eclipse but I much prefer using Sublime Text 3 and when I run the same program in Sublime from the terminal I get a symbol not found error during instantiation.
I don't know why I am getting a symbol not found error, can you please comment if you have any ideas on why this is happening or if you have any ideas on how to fix this?
I've included a screenshot.
On the left you can see my program HelloMain.java
Below HelloMain.java you can see my second class, Hello.java
Below Hello.java you can see my terminal where I attempt to run my program
On the right you can see the same files
HelloMain.java
Below HelloMain.java is Hello.java
Below Hello.java is the terminal where I run the program with the exact same issue
and below that is the program functioning through the console
Please let me know if you have any questions or need clarification.
Thank you.
All of my files were not being compiled. I run my code through zsh, my terminal doesn't automatically compile all or any files unless it is specified. "javac" compiles a file.
This line of commands compiled and ran my java files in a folder.
The package and folder of the files I am running are both called model and I am in a subdirectory when running these commands.
"javac **/*.java && java model.HelloMain".

Could not find or load main class hello

please, I really need some help with this! I'm working on my very first Java program - the classic "hello world" program. I saved the correct script on Notepad as Hello.java in C:\myProjects and used the command line to compile a Hello.class in the same folder. Even though the class is in the current directory, java still could not find it!
Here is a screenshot of the error message
Then I tried to manually set a classpath, even though I shouldn't need to do that, as seen here, but still the command line is not able to run the Hello.java program.
How do I fix this?? I even tried uninstalling and reinstalling my Java JDK altogether.
You need to capitalize Hello
Your command needs to be java Hello
Java is case sensitive.
or you might just install IntelliJ IDEA / Eclipse / NetBeans and enjoy life a little bit more :D
example step-by-step video (and there are tons more of those):
https://www.youtube.com/watch?v=ypLISBPwIWc

Error when executing class file in command prompt

I'm currently in the process of learning more about Java. I downloaded a sample program that has about 5 different .java files in the source folder.
Whenever I try to execute the class files in the command prompt using "java ClassNameHere", I get a message in the cmd prompt that says "Error: Could not find or load main class ClassNameHere".
I've tried recompiling them using the javac command and they compiles without any issues. Its just the class file i'm having trouble with.
In addition to this, I also cannot run the java files using Eclipse. Instead of getting an option to "Run as Java Application", "non applicable" appears under the "Run as" tab in Eclipse.
I've tried a number of different solutions already posted online, including another command that uses "java -cp . ClassNameHere" or something along those lines and they have not worked for me. Any help is appreciated.
Edit
Link to program from my drive since I'm not home
https://docs.google.com/file/d/0B9_pcTVZTnfEeVdzZmM0ZmFkTmc/edit?usp=docslist_api
Here is a a procedure that will get the application working in Eclipse. This procedure assumes the following:
Windows 8. I don't think Linux/Mac OS X procedure would differ greatly, but just in case...
In Eclipse:
Right click in Package Explorer, and select New --> Java Project.
In the New Java Project dialog, uncheck Use default location, and click Browse and select the directory you've extracted the zip to, or type the path in the box.
Click Finish.
From this point, you can run this is a Java Application from Eclipse.
Confirm that at least one of the classes has a main() method. That would be required for Eclipse to show "Run as Java Application".
Follow this steps:
Run Command Prompt.
Use cd C:\path\to\your\porject\java classes.
Use set path=%path%;C:\Program Files\Java\jdk1.7.0_65\bin (CHANGE THE PATH TO YOUR jdk1.x.x_xx\bin FOLDER) to tell the system where to find jdk programs.
Use javac MainClass.java to compile the project, MainClass.java si the java class where the main method is.
Use java MainClass (WITHOUT .java EXTENSION) to run the project.
After the last command your project should run correctly.
Sorry for the "use" ripetition but i'm not english.

VLCJ: Packaged Jar cant load libvlc library when double-clicked but runs perfectly through console

I have a problem with vlc.I am using Eclipse and have made a small application to play video files using vlcj framework.Inside Eclipse everything works fine but when I make jar executable file through Eclipse and double-clicking it (on Windows 64: Tested only on this platform) nothing happens .Then I'm trying using "cd myjarfilepath" and then "java -jar myjarname.jar" and everything works fine.Why this is happening and how to solve it?
Thanks in advance to stackoverflow's community .
Edit:
In Path Location: C:\Users\user\Documents\31\Latest_Win64\Needed I have the following files:
plugins(directory)
axvlc.dll
axvlc.dll.manifest
libvlc.dll
libvlc.dll.manifest
libvlccore.dll
npvlc.dll
npvlc.dll.manifest
vlc.exe.manifest
In my classpath i have included the following files:
jna-3.5.1.jar
platform-3.5.1.jar
vlcj-2.2.0.jar
vlcj-2.2.0-javadoc.jar
vlcj-2.2.0-sources.jar
This sounds like an issue loading the needed VLCj files. Not only are dlls required but the plugin directory is also required. As the execution location moves around from inside eclipse to back in the file system, the path to these files may be getting set incorrectly.
It sounds like you have it working within eclipse. This would indicate to me that what you have should work. Firstly, I would recommend acquiring the VLC dlls, etc., by providing this as a VM argument such as shown below, rather that setting it in code. Remember to comment out any loading you are doing in your code so that you are relying on the command line argument.
-Djna.library.path={Application Location}/lib
example: -Djna.library.path=C:/myapp/lib
Directory Contents:
lib
-- libblc.dll
-- libvlc5.dll
-- {etc}
/plugins
/3dnow
/access
{etc}
If you are still having issues, add the following argument to put VLCj into debug mode. This can be very helpful to determine where things are failing.
-Dvlcj.log=DEBUG
Hope that helps.

Java program unable to execute from command prompt

I recently installed a java software in my PC and started writing some simple programs. I didn't face any problem while compiling the programs, but while executing it, it shows this error message -
"Windows can't open this file.
File: HelloWorld.java
To open this file, windows need to know what program you want to open it. Windows can go online to lookup it automatically, or you can manually select from a list of programs that are installed on your computer.
I know all the path settings are correct. In fact, there was no problem at all while compiling the program. What can be the problem of this? I even reinstalled JRE and that didn't help. Can someone help me?
Note: I'm using Windows 7 64 bit architecture OS and I'm using command prompt for compilation and execution of the file.
I'll assume that you've double-clicked the .java file, e.g. in the file explorer. A java source file isn't a (click-launchable) executable, and - without some acrobatics - neither is a compiled .class file: you shouldn't expect to double-click either and start your program.
In order to get this sort of behavior, you'll need to build a launchable program, and there are a few ways to do this. One is by making a batch file that runs the java VM with your code, another is creating an executable jar file.
To just run your code outside your IDE, you can invoke the java VM on the command line:
c:\> java HelloWorld
As to your specific error message, you haven't associated any program with .java files. Typically, as programmers, we want this Windows file association to be our editor of choice or our IDE. You can create this association by Right-clicking on the file, choosing Properties from the menu and then clicking the Change button beside Opens with: to pick an application.
But this is a side-issue: you still won't use this to make .java file executable. Search around this site for questions and answers about building executable jar files. If you're using a specific IDE like Eclipse or NetBeans, use that to refine your search.
When you want to execute the program, you specifiy the class name rather than the file name:
java HelloWorld
Don't use java HelloWorld.java, for instance.

Categories