run time error....?
i m running a program in Java but i getting an error when i run it ...
the error is
java.lang.NoSuchMethodError: main
Exception in thread "main"
Java Result: 1
The code for the program is
public class PrintClass {
int x=0;
int y=1;
void printMe() {
System.out.println("X is " + x + ", Y is " + y);
System.out.println("I am an instance of the class " +
this.getClass().getName());
}
}
/** Creates a new instance of PrintClass */
class PrintSubClass2 extends PrintClass {
int z = 3;
void printMe() {
System.out.println("x is " + x + ", y is " + y +
", z is " + z);
System.out.println("I am an instance of the class " +
this.getClass().getName());
}
public static void main(String args[]){
PrintSubClass2 obj = new PrintSubClass2();
obj.printMe();
}
}
I need some help ...
[953 byte] By [
rasika] at [2007-11-27 8:20:44]

Your public class PrintClass doesn't have a main method. Your non-public class PrintSubClass2 does. Since you can't run a non-public class, the vm can't find any main method.
Actually the keyword " extends " connects the PrintSubClass2 to PrintClass...So it behaves as a public class now , i guess... So please check once ?Thanks...
rasika at 2007-7-12 20:09:06 >

> Actually the keyword " extends " connects the
> PrintSubClass2 to PrintClass...
> o it behaves as a public class now , i guess... So
> please check once ?
> Thanks...
Wrong. Classes don't inherit access modifiers, so the subclass is only as accessible as it's declared, meaning it's package-private in your example. If you want to run the subclass, you'll have to make it public.
it will be a gr888 help if u modify the program to run it correctly ....?thanks...
rasika at 2007-7-12 20:09:06 >

> it will be a gr888 help if u modify the program to> run it correctly ....?> thanks...Uhhh, no. All you have to do is add one word to one class, which you've already done to a different class.
> gr888 So Tony The Tiger text messages, does he?
srry , i didn't get u... can u clarify it ...
rasika at 2007-7-12 20:09:06 >

> srry , i didn't get u... can u clarify it ...Theyrrrrrrrrrrrrrrrrrrrrrrre Great!
> srry , i didn't get u... can u clarify it ...Here you go:1) do your own work. If you don't do it, you won't learn it.2) type in standard english. for many here, english is a second language.Clear enough?
> > srry , i didn't get u... can u clarify it ...
>
> Here you go:
> 1) do your own work. If you don't do it, you won't
> learn it.
> 2) type in standard english. for many here, english
> is a second language.
>
3) always eat a balanced breakfast
class PrintClass
{
int x=0;
int y=1;
void printMe()
{
System.out.println("X is " + x + ", Y is " + y);
System.out.println("I am an instance of the class " +this.getClass().getName());
}
}
public class PrintSubClass2 extends PrintClass
{
int z = 3;
void printMe()
{
System.out.println("x is " + x + ", y is " + y +", z is " + z);
System.out.println("I am an instance of the class " +this.getClass().getName());
}
public static void main(String args[])
{
PrintSubClass2 obj = new PrintSubClass2();
obj.printMe();
}
}
try this way i think it will work
it should be name as PrintSubClass2.java
I got it. Thanks.
rasika at 2007-7-12 20:09:06 >

> I got it. > Thanks.No you didn't! You just pouted and whined until someone did it for you. Try learning and understanding in future.
> srry , i didn't get u... can u clarify it ...cn u wrt nglsh?
jverda at 2007-7-21 22:36:56 >

> Actually the keyword " extends " connects the
> PrintSubClass2 to PrintClass...
> o it behaves as a public class now , i guess
Three seconds of logical thinking would tell you that this is cannot be so.
All classes descend from Object. Object is public. Therefore, if what you said were true, all classes would always be public.
jverda at 2007-7-21 22:36:56 >

> > srry , i didn't get u... can u clarify it ...
>
> Here you go:
> 1) do your own work. If you don't do it, you won't
> learn it.
> 2) type in standard english. for many here, english
> is a second language.
>
> Clear enough?
It seems surkum hasn't learned rule number 1 yet. He's a walking ID-Ten-T Error.