This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Error File not found

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Im new to the forum and new to forums in general, let me know if i am putting the code up wrong. im also new to programming, I will  be grateful to anyone who can help me , i just started a course lately to learn java and i am trying to compile/run some code that the course supplied but i cant get it to compile. To me it looks like it cant find the file  Chap7Part3 but i can see the file in the folder. the message im getting in dos is

C:\Users\FiercePC\Documents\java>javac Chap7Part3.java
error: file not found: Chap7Part3.java
Usage: javac <options> <source files>
use --help for a list of possible options

C:\Users\FiercePC\Documents\java>



My java is




I have also attached an image of my java folder
Screenshot-2019-07-20-22.17.44.png
[Thumbnail for Screenshot-2019-07-20-22.17.44.png]
 
Johnny Quinn
Greenhorn
Posts: 9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see now i saved the file as .txt
 
Marshal
Posts: 65050
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Well done finding the problem, but don't put your own work and java.exe in the same folder. It is usual to put java.exe in a subfolder of Program Files, and you add that to your system PATH environment variable.
 
Campbell Ritchie
Marshal
Posts: 65050
247
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code should go after the first ] and before the second [ in the code tags; if I correct your code tags you will see how much better it looks
 
Johnny Quinn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Welcome Well done finding the problem, but don't put your own work and java.exe in the same folder. It is usual to put java.exe in a subfolder of Program Files, and you add that to your system PATH environment variable.



Thanks Ritchie, It’s not easy troubleshooting. I added to the Path environment variable when I setup java, the reason I put the java.exe in that folder was because i couldn’t compile or run a program otherwise. I am obviously doing something wrong ? Path related ?
 
Sheriff
Posts: 6109
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through this Wiki:

https://coderanch.com/wiki/659740/create-Java-program

It will answer many questions.  Good luck!
 
Campbell Ritchie
Marshal
Posts: 65050
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch There are other places you can buy the same book, but you can get the ebook, for less than a pbook, directly from the publishers.
 
Johnny Quinn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:Go through this Wiki:

https://coderanch.com/wiki/659740/create-Java-program

It will answer many questions.  Good luck!


Thanks for that Knute , I think I have everything set up correctly now
 
Campbell Ritchie
Marshal
Posts: 65050
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done

If you can get sensible relpies to the following two instructions at the command line, you will be in action The version number for javac shouldn't be bigger than that for java.
 
Johnny Quinn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Well done

If you can get sensible relpies to the following two instructions at the command line, you will be in action The version number for javac shouldn't be bigger than that for java.



im getting the expected response form java and javac,

java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)

javac 12.0.2

i can compile my code but then it wont run. As an example i can compile this code but when i try to run it i get this message. C:\Users\FiercePC\Documents\java>java HelloWorldToday.java
Error: Could not find or load main class HelloWorldToday.java



Here are my files and the class file is there, what am i doing wrong. Im at a loss
Screenshot-hello.png
[Thumbnail for Screenshot-hello.png]
Screenshot-home.png
[Thumbnail for Screenshot-home.png]
 
Campbell Ritchie
Marshal
Posts: 65050
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Johnny Quinn wrote:. . . java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)

javac 12.0.2

If you get to find the appropriate XYZ.class file, you will get a exception about unsupported class version. There are two common explanations for that problem:-
  • 1: You haven't set up the PATH environment variable correctly.
  • 2: You downloaded a JRE (=runtime environment) rather than a JDK (=development kit). I am not certain it is possible to make this mistake with Java12, however.
  • Please show us the contents of your PATH:Make sure your ...jdk-12.0.2....part appears before anything else that might contain a java.exe program. We usually recommend that part of the PATH go first.

    . . . Error: Could not find or load main class HelloWorldToday.java . . . what am i doing wrong. Im at a loss

    Try the following option, when the command line is pointing at the folder containing the XYZ.class file:-
     
    Johnny Quinn
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:

    Johnny Quinn wrote:. . . java version "1.8.0_221"
    Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
    [/list]Please show us the contents of your PATH:
    here it is

    C:\Users\FiercePC>echo %PATH%
    C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\PuTTY\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Calibre2\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Java\jdk-12.0.2\bin;C:\Program Files\Java\jre1.8.0_221\bin;C:\Users\FiercePC\AppData\Local\Microsoft\WindowsApps;

     
    Johnny Quinn
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator


    Make sure your ...jdk-12.0.2....part appears before anything else that might contain a java.exe program. We usually recommend that part of the PATH go first.

    . . .

    Apologies but i dont understand waht you are telling me.  

     
    Campbell Ritchie
    Marshal
    Posts: 65050
    247
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Useful information thank you.

    Have a look in the C:\Program Files (x86)\Common Files\Oracle\Java\javapath folder and see if there isn't a java.exe program in there. As you see, your ...jdk-12.0.2.... directory appears long after that. If you are compiling with a Java12 version, and trying to run Java® with a Java8 version, your program won't run. See if you can move the part including ...jdk12.0.2.... first in the PATHs. Move the part starting with the drive letter (C) and ending bin.
    Now, about the file not found problem. Please repeat the procedure but slightly differently (sorry, I forgot to ask this earlier):-Did you have any luck with the -cp . option? Did you set a system CLASSPATH? That usually causes more trouble than it is worth, and can cause you not to find the file sought.
     
    Campbell Ritchie
    Marshal
    Posts: 65050
    247
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am not used to changing PATHs on Windows10 (I hardly ever use Windows®) but what you want is for the total PATH to read this:-

    C:\Program Files\Java\jdk-12.0.2\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\PuTTY\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Calibre2\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Java\jdk-12.0.2\bin;C:\Program Files\Java\jre1.8.0_221\bin;C:\Users\FiercePC\AppData\Local\Microsoft\WindowsApps;  

    or:-

    C:\Program Files\Java\jdk-12.0.2\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\PuTTY\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Calibre2\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\FiercePC\AppData\Local\Microsoft\WindowsApps;  

    The first version contains ...jdk-12.0.2.... twice and the second version only once. You don't need both JRE and JDK, only the JDK, but it don't think it will do any harm to have them both, nor to have the same thing twice in your PATH.

    Only change the ...jdk12.0.2.... part; if you notice anything else I have changed, assume that is a mistake of mine.
     
    Campbell Ritchie
    Marshal
    Posts: 65050
    247
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I think the PATH setting wizard for Win10 gives you a line for each entry. Don't try squeezing two things onto the same line. See if you can move the ...jdk12.0.2.... line up to the top.
     
    Johnny Quinn
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:
    Please repeat the procedure but slightly differently (sorry, I forgot to ask this earlier):-


    this is the result i got
    %CLASSPATH%

    Did you have any luck with the -cp . option?
    Is this what  you were asking me to do put this in dos java -cp.HelloWorld?

    Did you set a system CLASSPATH?
    Not that i remember

    As for your other recommendation i will try and figure out what you are telling me and edit my path.

     
    Johnny Quinn
    Greenhorn
    Posts: 9
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Not sure exactly how but i deleted one of the java paths and moved the java bin path to top of list and everything seems to be working, thanks for you time helping me Ritchie it is appreciated.
     
    Saloon Keeper
    Posts: 6040
    58
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    To simplify environment variable maintenance over time, I created a new system environment variable:
    JAVA_HOME=C:\Program Files\Java\jdk-12.0.2

    And then modify the PATH environment to be:
    PATH=%JAVA_HOME%\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32 ....

    That way you only have to change JAVA_HOME when you install a new version. You shouldn't need to modify PATH when you install updates.
     
    Campbell Ritchie
    Marshal
    Posts: 65050
    247
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Johnny Quinn wrote:Not sure exactly how . . . everything seems to be working, thanks for you time helping me Ritchie . . .

    That's a pleasure . If you didn't set a CLASSPATH, that's why you are getting that response, and at least you don't have a CLASSPATH error. Carey's suggestion about JAVA_HOME is a good idea; you will have to use JAVA_HOME for some IDEs when you have enough experience to move off text editors.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!