• 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

not able to run my first java program

 
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my program is able to pass the compilation test.but when i run the program its gives error

"C:\Users\DHRUV\My Documents\java>javac innerclass.java

C:\Users\DHRUV\My Documents\java>java innertest
Error: Could not find or load main class innertest

here the file name is innerclass.java and the main class name is innertest.

kindly help me out
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I know, The file name should match the name of class. Try with that...
 
dhruv garg
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
file name should be same as main class only when the main class is public.
anyways i changed the file name too but its not working.
 
vinayjg kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post your code?
 
dhruv garg
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is happening with every program.
if you want to see my code you can see but i think it will be of no use.there must be some problem with system...i dont know...

here is the code:-

class A
{
private int a;
A(int a)
{
this.a =a;
}
void show()
{
System.out.println("a="+a);
} // End of show()
}// End of class A
public class innertest
{
public static void main(String args[])
{

A a1 = new A(20){
public void show()
{
super.show();
System.out.println("Hello");
}
public void display()
{
System.out.println("Hi");
}
};
a1.show();
// a1.display();
}
}
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dhruv, You got to check this tutorial to help you with your first java program.

And please UseCodeTags for posting the code. That way it makes the code more presentable and readable. You can your post and add the code tags
 
dhruv garg
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i did what was told in the tutorial but still my program is not working
 
dhruv garg
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it is happening with every program....not with a particular program
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you set the classpath variable? If yes what is the value that you have set?
 
dhruv garg
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your advice. i didnt reboot my system after changing the path and JAVA_HOME variables. now every thing is working fine.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

dhruv garg wrote:thank you for your advice. i didnt reboot my system after changing the path and JAVA_HOME variables. now every thing is working fine.



I dont think a reboot is required. Just restarting the terminal/cmd should work Anyways glad that you got it working
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mohammed was on about classpaths, but you need to realise that setting a system classpath can cause more harm than good. If you don’t already have a system classpath, leave well alone.
 
Ranch Hand
Posts: 1087
Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a possiblity that a virus can infect the JDK in the System?

I had a simple netbean application and when i tried to run that application the page was blank i just restarted the machine and it was working fine
 
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic