• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error:could not find or load main class

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am trying to run this program in eclipse but getting error , i don't know what i am doing wrong?


public class Test  extends Thread{
   
public void run() {
System.out.println("start thread");
}


public static void main(String[] args) {

test t =new test();
t.start();

}

}


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

i have recently downloaded Jdk 15.0.2 in my machine and have noticed it doesn't have jre included . i did set Path ,but couldn't set the CLASSPATH. i don't know it is revelant here but thought of mentioning it.
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing it didn't compile. In some places you have 'test' with a lower case 't', and others an upper case 'T'. Java is case sensitive.
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am sorry i will edit it , it was all lower cases "t" i copied wrong! still learning how to post!!
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java conventions say that class names Must begin with an upper case letter.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't edit old posts once people have responded to it. Write a new one.
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry about that
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We're good.

Do you want to repost your edited code again?
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class Test  extends Thread{
   
public void run() {
System.out.println("start thread");
}


public static void main(String[] args) {

Test T =new Test();
T.start();

}

}

tried again , still same error
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so two things:

First, it compiled and ran for me so it must have something to do with your project layout or Eclipse configuration. Can you show/tell us what the project hierarchy is? Do you have any compilation errors? How are you running it? I'm presuming by going to your project explorer tab and right clicking on Test.java then selecting Run As > Java Application.

Secondly, Another  Java conventions is that variable and method name must begin with a lower case letter.
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The last couple of Java releases do not include a JRE so you have to configure the JDK in its place in Eclipse.
Window > Preferences > Java > Installed JREs
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Please don't edit old posts . . ..

I have reversed the edit.

And welcome to the Ranch
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Ok, so two things:

First, it compiled and ran for me so it must have something to do with your project layout or Eclipse configuration. Can you show/tell us what the project hierarchy is? Do you have any compilation errors? How are you running it? I'm presuming by going to your project explorer tab and right clicking on Test.java then selecting Run As > Java Application.

Secondly, Another  Java conventions is that variable and method name must begin with a lower case letter.



i also think it is something related to eclipse configuration i don't know what to do about it, i didn't get any compilation error, i am running by pressing the run button.
i created a package and then in it i created a class named Test class
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you muck with a CLASSPATH somewhere?
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Did you muck with a CLASSPATH somewhere?


what does that mean? i haven't set any ClASSPATH
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what I mean.

Did you set the JRE ?
Window > Preferences > Java > Installed JREs

You'll use the JDK because there is no JRE.
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you help me how to add jre files? like which path to copy?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you on Windows operating system?
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes
i added c:\programfiles\java\jdk 15.0.2
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you go to
Window > Preferences > Java > Installed JREs
and select ADD
and put in that path
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes i added the path I mentioned above
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
unfortunately yes
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of clicking the Run button have you tried right clicking on Test.java and selecting Run As > Java Application ?
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
showing launch error
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have any other programs in Eclipse that do run?

Did the launch error have any further description?
 
anubha pali
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are correct -now i am getting launch error in. every program, actually i have installed eclipse in new machine 2 days ago and started with that thread program. in this machine i have only used command prompt which is working fine
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Eclipse version 2020-12 ?

A small possibility. Wherever you installed Eclipse.exe there's a file eclipse.ini, edit the -vm parameter in this file to be:

-vm
C:/Program Files/Java/jdk-15.0.2/bin
 
anubha pali
Greenhorn
Posts: 14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally figured out , i deleted eclipse and again installed it then went to
Preference > Installed JREs > add > standard VM> Directory > where java is installed (C:\Java\jdk-15.0.2) > Finish
then,
Preference > Installed JREs > execution environment > JavaSE-15 > choose jdk-15.0.2> apply
then done!
 
reply
    Bookmark Topic Watch Topic
  • New Topic