Symbol Not Found - Sublime Text 3 - - java

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".

Related

Why isn't my code running in VisuaStudioCode?

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.

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

Running a simple Java Program in Command Prompt error

I am trying to run my Example2.class program in windows 7 64-bit command prompt. I used command prompt already to compile the program, but when type: "java Example2" it gives me an error saying could not find or load main class example2. How do I set the right path to my file so that it can find it? Thanks
You need to give it the full package name, and (unless you change the class path) you need to be in the right directory. If the full package name is
com.something.Example2
then you'd expect the compiler to produce a file like this:
com/something/Example2.class
If you make sure you're in the directory immediately above com (i.e., you can see com when you do a directory listing), then you can run it with
java com.something.Example2
Note that it's case sensitive.
If you used the default package (i.e., the full class name really just is Example2) then you need to be in the directory containing Example2.class, and then you run
java Example2
But using the default package is discouraged.
The biggest thing you could do to help yourself out is to use an IDE (Eclipse or NetBeans are the most commonly used ones). As soon as you start to write anything at all large or complex, compiling and running from the command line without an IDE will cause you to claw your own eyes out.
When you write a class you can save the file as : MyClass.java and then execute this commands in this directory:
javac MyClass.java
which will compile the class and then create automatically the file: MyClass.class (If compilation ended without errors)
and then to run this SPECIFIC class execute the command:
java Myclass

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.

java compiling error "could not find or load main class main.java"

I understand there are a lot of threads similar to this one, but I couldn't find the one that solved my problem. Following this instruction I was able to get java in terminal and be able to compile. I am able to "javac main.java" with no errors, but when I "java main.java", it simply says it could not find or load main class main.java. I believe that my classpath is wrong but i'm not entirely sure how to fix this either. This is what comes out when I type in echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/taka/.rvm/bin
and when I type echo $CLASSPATH it doesn't show anything.
I have also tried java -cp ./ main.java as that seemed to have worked when I compiled and ran HelloWorld.java
If your javac is successful then update your classpath environment variable and add current directory i.e. . in the classpath, then run the java as below:
java main
Please note: There is no .java extension as you need to run .class file(which was generated after javac) that also without mentioning the extension. Java uses generated class files to execute not the original source files.
main.java java is your source code . you cant run java source without compile. For compilation you should use javac command. After that it will create a main.class file which can understand by interpreter which is java.
So you to run your class use java main or java main.class

Categories