• Post Reply Bookmark Topic Watch Topic
  • New Topic

cannot find the class file  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am new here, I have been looking on
Many different websites to find an fix to my issue. I am trying to run a program in the command prompt in java and it cannot find the class file. Please help.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so when it comes to problems like this, the details are critically important.  Did you compile the file? Do you see a class file? What directory are you in when you try to run it? What directory is the class file in?  Are you using a package statement?  What EXACTLY is the error you get? Did you define a CLASSPATH environment variable, and if so, what is it?

it's kind of hard to answer you without knowing the answer to at least some of these. So let's start with:

Where is your class file?
What directory are you in when you run "java <class name>"?
What EXACTLY are you typing in your command?
What EXACTLY does the error say>
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your class file?
What directory are you in when you run "java <class name>"?
What EXACTLY are you typing in your command?
What EXACTLY does the error say>

I don't know if it actually created a class file because I went to the directory in the command prompt where it is suppose to be and it only shows the hello world app
That I made without a class file. So I either can't find it or I didn't make one.

The directory I am in is C:\Program Files\java\java programs\bin

I was typing javac HelloWorldApp.java

It was "could not find or load main class"

Thank you
 
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
Pat Gareau wrote:. . . The directory I am in is C:\Program Files\java\java programs\bin
That is a mistake. Create your own directory and don't go into Program Files. Open the command line and give it the following two commands:-
mkdir java
cd java
You can of course use a different name for the directory. Next time use only the second line, and put your work in that java directory.
I was typing javac HelloWorldApp.java

It was "could not find or load main class"

Thank you
No, it wasn't. You never get that error message from the javac tool. Use the dir command and find out whether your directory contains the HelloWorldApp.class file. If it does, then tell us what you get from
echo %CLASSPATH%
You have probably made the mistake of setting a CLASSPATH environment variable. I know some books tell you to do that, but that advice is mistaken. If you set the CLASSPATH, delete it; if you didn't set it edit it to start .; by adding dot‑semicolon to its beginning. There used to be applications (e.g. QuickTime) which set the CLASSPATH while you aren't watching and it causes no end of annoyance.
If the .class file isn't there, tell us what error messages you got from the javac tool and we shall do our best to sort it out. There are few compiler error messages we haven't sorted out.
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Users\Administrator\java

C:\Users\Administrator\java>C:\Users\Administrator\Desktop\java
'C:\Users\Administrator\Desktop\java' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Administrator\java>cd C:\Users\Administrator\Desktop\java

C:\Users\Administrator\Desktop\java>dir
Volume in drive C has no label.
Volume Serial Number is 86EE-9CE9

Directory of C:\Users\Administrator\Desktop\java

01/10/2017  09:03 PM    <DIR>          .
01/10/2017  09:03 PM    <DIR>          ..
01/07/2017  08:16 PM               152 HelloWorldApp.java
               1 File(s)            152 bytes
               2 Dir(s)  423,627,943,936 bytes free

C:\Users\Administrator\Desktop\java>HelloWorldApp.java

C:\Users\Administrator\Desktop\java>javac HelloWorldApp
error: Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested
1 error

C:\Users\Administrator\Desktop\java>java HelloWorldApp
Error: Could not find or load main class HelloWorldApp

C:\Users\Administrator\Desktop\java>

this is what my command prompt screen looked like...
 
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it looks,from your command prompt history,that the HelloWorldApp did not compile.
as i can see the HelloWorldApp.java(the source file)  is in the directory → C:\Users\Administrator\Desktop\java
follow the procedures,in command prompt:
1.) cd C:\Users\Administrator\Desktop\java
2.) javac HelloWorldApp.java
3.) if it compiles you will not get any message,if it doesn't then it will give you some error message.
4.) if it compiles type→%CLASSPATH%
5.) show us this complete session of your command prompt.
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>cd C:\Users\Administrator\Desktop\java

C:\Users\Administrator\Desktop\java>javac HelloWorldApp.java

C:\Users\Administrator\Desktop\java>%CLASSPATH%
'%CLASSPATH%' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Administrator\Desktop\java>java HelloWorldApp
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

C:\Users\Administrator\Desktop\java>
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Gareau wrote:
C:\Users\Administrator\Desktop\java>javac HelloWorldApp
error: Class names, 'HelloWorldApp', are only accepted if annotation processing is explicitly requested
1 error

C:\Users\Administrator\Desktop\java>java HelloWorldApp
Error: Could not find or load main class HelloWorldApp

C:\Users\Administrator\Desktop\java>

this is what my command prompt screen looked like...


Take a directory listing *after* you run the "javac" command (Java compiler). You will see that there *still* isn't a HelloWorldApp.class file. This is because the Java compiler failed to compile the java file (mainly because you didn't specify a java file).  And without a class file, well, the "java" command will complain about not finding the class file.

Henry
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops... wasn't paying attention to the timestamps...

Pat Gareau wrote:
C:\Users\Administrator\Desktop\java>java HelloWorldApp
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.


This is caused by a mis-configuration. Likely you have both Java 7 and Java 8 installed in your environment. You are using the compiler from one, and the JVM from the other. Also, there is probably auto update going on too, that is confusing stuff even more.

Unfortunately, there isn't an easy way to fix this... meaning a way that will work for every case. You need to find (and tell us) the location of the Java 7 installation, the location of the Java 8 installation, and show us the PATH environment variable you are using. The order in the PATH may need to change.

Note: It isn't as easy as simply deleting one of the installations because you may have something in your environment that is dependent on a particular version.

Henry
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have java 8 installed in the program files folder on one account, in another account I have both 7 and 8 in program files.
the path environment is C:\Program Files\Java\jdk1.8.0_111\bin
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pat i mistype one thing please follow my same instructions but change the %CLASSPATH% to "echo %CLASSPATH%".
Show me again..
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as i can see your source code is compiled.we just need to find the classpath.
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>cd C:\Users\Administrator\Desktop\java

C:\Users\Administrator\Desktop\java>dir
Volume in drive C has no label.
Volume Serial Number is 86EE-9CE9

Directory of C:\Users\Administrator\Desktop\java

01/11/2017  06:36 AM    <DIR>          .
01/11/2017  06:36 AM    <DIR>          ..
01/11/2017  06:27 AM               201 DynInt.java
01/11/2017  06:08 AM               435 HelloWorldApp.class
01/10/2017  10:53 PM               160 HelloWorldApp.java
01/11/2017  06:36 AM               390 ScopeDemo.java
01/11/2017  06:20 AM               482 StrDemo.class
01/11/2017  06:20 AM               188 StrDemo.java
               6 File(s)          1,856 bytes
               2 Dir(s)  421,472,686,080 bytes free

C:\Users\Administrator\Desktop\java>javac HelloWorldApp java
error: Class names, 'HelloWorldApp,java', are only accepted if annotation processing is explicitly requested
1 error

C:\Users\Administrator\Desktop\java>javac HelloWorldApp.java

C:\Users\Administrator\Desktop\java>java HelloWorldApp
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

C:\Users\Administrator\Desktop\java> "echo %CLASSPATH%".
'"echo %CLASSPATH%".' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Administrator\Desktop\java> "echo %CLASSPATH%"
'"echo %CLASSPATH%"' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Administrator\Desktop\java>echo %CLASSPATH%
%CLASSPATH%

C:\Users\Administrator\Desktop\java>javacHelloWorldApp.java
'javacHelloWorldApp.java' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Administrator\Desktop\java>javac HelloWorldApp.java

C:\Users\Administrator\Desktop\java>java HelloWorldApp
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

C:\Users\Administrator\Desktop\java>





Here is the information you requested hopefully that is what you need.
 
praveen kumaar
Ranch Hand
Posts: 461
22
Android Chrome Eclipse IDE Google App Engine Java Notepad Oracle Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you have tried uninstalling the previous version of java or updated it or you have 2 versions.
anyway i have ask you to run the command "echo %CLASSPATH%".but you have not to include the inverted commas simply run these 2 commands.
echo %CLASSPATH%
and then
echo %PATH%
let us know.
in your case your HelloWorld.java has been compiled with version 1.8 and you are trying to run it on the JRE(runtime environment) 1.7,java is not forward compatible though
look in this thread.may be you will get some help from there.
May be i will not come online for some days.
Exams!
so some other will guide you to resolve your query...

Kind Regards,
Praveen.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't usually use Windows®, but I don't remember that error from my Windows® days. I thought the JVM throws an Exception if you try to execute Java8 bytecode on a Java7 runtime. Try the following two instructions at the command line and tell us what the responses (version numbers) are:-
 
Ranch Foreman
Posts: 3074
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's complaining about the registry, which implies that an uninstall/install has failed somewhere along the way, resulting in a corrupt deployment.
It's not the Java version error.

I'm not sure what steps need to be taken to fix it.  Maybe try a fresh install of JDK 8?
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>java -version
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.8', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

C:\Users\Administrator>javac-version
'javac-version' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Administrator>echo %CLASSPATH%
%CLASSPATH%

C:\Users\Administrator>echo %PATH%
C:\WINDOWS\System32;C:\Program Files\Java\jdk1.8.0_111\bin

C:\Users\Administrator>good  luck on your exams Praveem and thank you all for your help so far, I will try comepletely deleting java 7 and 8 off of my computer and then reinstall 8 and see what happens.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Gareau wrote:. . .
C:\Users\Administrator>javac-version
'javac-version' is not recognized as an internal or external command,
operable program or batch file.
That suggests there is an error in the PATH or you don't have the javac tool in that PATH. When you installed Java®, did you install a JRE or a JDK? The JDK is bigger and includes javac; the JRE is smaller and doesn't include javac. You need the JDK.
C:\Users\Administrator>echo %CLASSPATH%
%CLASSPATH%
I think that means you have correctly deleted your CLASSPATH, so leave the CLASSPATH alone since that looks probably correct.
C:\Users\Administrator>echo %PATH%
C:\WINDOWS\System32;C:\Program Files\Java\jdk1.8.0_111\bin
. . . .
There is something suspicious about that PATH; all Windows® PATHs I have seen seem longer than that, so I am wondering whether you have inadvertently lost part of the original PATH. Are you using a 32‑bit machine? Try editing the PATH so the entry for Java comes before with System32 entry. There might be an old JRE in System32 which will cause problems if you have a newer javac tool.

Try editing the PATH like that before you reinstall everything.
 
Dave Tolls
Ranch Foreman
Posts: 3074
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:That suggests there is an error in the PATH or you don't have the javac tool in that PATH. When you installed Java®, did you install a JRE or a JDK? The JDK is bigger and includes javac; the JRE is smaller and doesn't include javac. You need the JDK.


Well, it actually suggests that there is a space missing between 'javac' and '-version'.
;)
 
Sheriff
Posts: 4935
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Well, it actually suggests that there is a space missing between 'javac' and '-version'.
With an age eyesight gets better? Have a cow.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damn! Usually with my brain malfunctioning, I see things that aren't there. Now I am not seeing things that aren't there, like that non‑space.
 
Sheriff
Posts: 4298
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:It's complaining about the registry, which implies that an uninstall/install has failed somewhere along the way, resulting in a corrupt deployment.
It's not the Java version error.

I'm not sure what steps need to be taken to fix it.  Maybe try a fresh install of JDK 8?

Personally, I would uninstall all Java versions before reinstalling.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good idea, but repeating the javac -version instruction with the space might be helpful.
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am pretty sure it's a 64 bit machine. I recently deleted the old path and put that path in there, I was following instructions I found on a website. After trying and reading so many different websites I realized I needed to get help from a forum.
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pat Gareau wrote:. . . instructions I found on a website. . . . .
Please tell us which website so we can avoid assess it.
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.javatpoint.com/how-to-set-path-in-java

Also in a previous reply someone mentioned to delete the jdk. I have netbeans on my computer and was unable to delete that...
 
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Pat Gareau wrote:. . . instructions I found on a website. . . . .
Please tell us which website so we can avoid assess it.

You were right with "avoid it". It says stuff like:
If you are saving the java source file inside the jdk/bin directory, path is not required to be set because all the tools will be available in the current directory.

 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The website link (thank you ) tells you how to set a user PATH not a system PATH, which means the PATH to Java® is only available to one user, but it doesn't say to delete anything from the existing PATH, so I think you have misunderstood something. It also tells you to add the PATH to the jdk installation at the end of the PATH on Linux, whereas it is probably better to add it at the start:-
That webpage wrote:export PATH=$PATH:/home/jdk1.6.01/bin/
Since most Linux installations have a Java® runtime (and maybe also a JDK) by default, you will find the default This would be better:-
export PATH=/home/jdk1.6.01/bin:$PATH
That is an old version which came out over ten years ago. It also contains an unusual number; it would usually be 1.6.0_01 not 1.6.01.
Maybe the webpage is not quite as bad as I thought. No, Tony has noticed something else bad. I am surprised by how many websites give misleading or positively bad advice. If I give you bad advice, don't worry, because there are enough people here who know what they are doing and will tell me off. Or if I don't not see spaces which aren't there
Watch how your computer behaves; if you find there are programs which don't run, post here and I am sure somebody will be able to help you reinstate whichever part of your PATH is missing.

Now, let's get back to your Java® problem. Did you get a sensible response to javac -version with the space? I don't know why you are getting the discrepancy between your installed version of Java® and what the registry expects. Knute is right to suggest you uninstall (not delete) the older versions of Java®, which you can do via Control Panel→Programs, before reinstalling Java®. If that doesn't cure your problem, I don't know what to suggest myself, but I am sure somebody will be able to help.
Java® downloads link
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I don't know why you are getting the discrepancy between your installed version of Java® and what the registry expects.

This looks like a case of installing Java 7 and then 8 and then manually deleting (or possibly moving or renaming) the Java 8 installation rather than uninstalling it.

I also agree with Knute, properly uninstall all your Java installations (using the procedure Campbell outlined). You might also want to consider uninstalling NetBeans just to be sure (make sure you have backed up any important data before uninstalling). Finally reinstall Java 8, test it is working from the command line and then reinstall Netbeans.
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you want me to just type javac -version into command prompt? If so I did that and it gave me 'javac' is not recognized as an internal or external command,
operable program or batch file. . A few of you mentioned a space issue somewhere? Thank you for all your help so far..log
When I try to uninstall netbeans it gives me error It appears that the following instance of the netbeans ide is still running C:\Program Files\Netbeans 8.0.2 A lock file exists at C:Users\patga\AppData\Roaming\Netbeans\8.0.2\Lock Please close this Netbeans IDE prior to continuing with uninstallation. You can get more details about the issue in the installer log file C:\Users\patga\.nbi\log\20170113063037.log
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Restart your computer and on starting immediately uninstall NetBeans. If that still fails press CTRL+ALT+DEL and select "Start Task Manager". Click the "Applications" tab and see if NetBeans is listed. If so select it and press "End Task". If not select the "Processes" tab and find the NetBeans process that is running, select it/them and press "End Process". Now try to do the uninstall.
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ty everyone my problem has been fixed,
Appreciate everyone's help!!!
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done Please tell us what the solution was.
 
Pat Gareau
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I downloaded the previous version 1.7 and that seemed to be it, been working good so far
 
Campbell Ritchie
Marshal
Posts: 56610
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!