Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not able to run my first java program

 
dhruv garg
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
  • 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
 
vinayjg kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Can you post your code?
 
dhruv garg
Greenhorn
Posts: 7
Java
  • Mark post as helpful
  • send pies
  • 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();
}
}
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
it is happening with every program....not with a particular program
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • 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
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • 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.
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic