Reply from brosegh on May 23 at 9:58 AM CallMethod() is in the class TestException. Even though the method is defined as static, you still need to specify the class name. If the method was not static, you would have to create an object of that type: TestException te = new TestException(); te.CallMethod(); Since the method is static, you don't do that. Instead you do the following: TestException.CallMethod();
| | | ---------------Original Message--------------- From: deepa Sent: Wednesday, May 23, 2012 5:48 AM Subject: Exception in Thread 'main' java.lang.NoSuchMethodError:main Exception in Thread 'main' java.lang.NoSuchMethodError:main class Myexception extends Exception { int i=0; public Myexception(int i) { this.i=i; } public String toString() { return"Exception for the input"+i; } } class TestException { public static void CallMethod(int i)throws Myexception { System.out.println("computing value of "+i); if(i<5) { System.out.println("msg"); throw new Myexception(i); } } public static void main(String args[]) { try { CallMethod(7); }catch(Myexception e) { System.out.println(e); } } } | | Reply to this email to post your response. __.____._ | _.____.__ |
No comments:
Post a Comment