Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

receiving Error: Could not find or load main class A

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have installed JDK 11.5;created a simple program; compiled using javac that created class file "A"

Upon running the java class file A from command prompt, receiving below error:

#############################
Error: Could not find or load main class A
Caused by: java.lang.ClassNotFoundException: A
##############################

Read that JDK 11 does not need JRE, but how can i run the class file without jvm/jre? Please help.
 
Marshal
Posts: 76479
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please show us the path and the contents of the directory you are in, also whether you have a package declaration in that class, and the results of the following two instructions:-It is incorrect that Java11 doesn't supply a JRE. The JRE is part of the JVM you downloaded. Java11 no longer supplies a separate JRE; that is something different.
Don't say you are running a class. You cannot run classes, only methods.
 
Rupa Kondapalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The issue is resolved after pointing the classpath to the right directory having class files.

Yes, I am running a class not method. Not sure, the difference as of now. Just started learning java. Will dig more into it. Thank you for mentioning.  
 
Campbell Ritchie
Marshal
Posts: 76479
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rupa Kondapalli wrote:The issue is resolved after pointing the classpath to the right directory having class files.

No, it isn't. By changing the CLASSPATH you have enabled your current program to run, but the changes are probably storing up more trouble for the future.

Yes, I am running a class not method. . . .

When you write java A you aer telling the JVM to find the main() method in class A and run that method. That method will doubtless run other methods.

By the way: A is a very poor name for a class; I hope your book doesn't tell you to use such names.
 
Rupa Kondapalli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, I thought classpath should point to the directory having .class files. If not, please suggest what it should be.

Here are:
echo %path%
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Java\jdk-11.0.5\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;

echo %classpath%
C:\Users\user\Desktop\Rupa\Java;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;

P.S: After compiling my java program, by default it gave the class file name as 'A'. I ran it w/o renaming to see the output.

 
Campbell Ritchie
Marshal
Posts: 76479
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rupa Kondapalli wrote:Okay, I thought classpath should point to the directory having .class files. . . .
echo %classpath%
C:\Users\user\Desktop\Rupa\Java;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;

How much of that CLASSPATH was added automatically when you installed SSH or PowerShell and how much did you add by hand? Remove everything you added yourself, but leave whatever SSH and PowerShell added for you. Add “.;” to the start of the CLASSPATH, since you will usually be running from the . directory (=current working directory) at the command line.
If you need a different CLASSPATH it is better to use the -cp option because the changes will be different for every program you run.

P.S: After compiling my java program, by default it gave the class file name as 'A'. I ran it w/o renaming to see the output.

You mean you wrote a class called A and you then got a file called A.class?
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic