Nagendran
NoSuchMethodException
1 Answer(s)      a year and a month ago
Posted in : Java Interview Questions

whis is the NoSuchMethodException in java? or define NoSuchMethodException with exp?

View Answers

March 28, 2012 at 1:46 PM


This Exception occurs when the method you call does not exist in class.

Example

import java.lang.reflect.Method;

public class JavaReflectionExample2
{

  public JavaReflectionExample2()
  {
    Class c;
    try
    {
      c = Class.forName("java.lang.String");
      try
      {
        Class[] paramTypes = new Class[5];
        Method m = c.getDeclaredMethod("fooMethod", paramTypes);
      }
      catch (SecurityException e)
      {
        e.printStackTrace();
      }
      catch (NoSuchMethodException e)
      {
        e.printStackTrace();
      }
    }
    catch (ClassNotFoundException e)
    {
      // deal with the exception here ...
      e.printStackTrace();
    }
  }

  public static void main(String[] args)
  {
    new JavaReflectionExample2();
  }

}









Related Pages:
NoSuchMethodException
NoSuchMethodException  whis is the NoSuchMethodException in java? or define NoSuchMethodException with exp?   This Exception occurs when... (NoSuchMethodException e) { e.printStackTrace(); } } catch
NoSuchMethodException even if method defined - Java Beginners
NoSuchMethodException even if method defined  Hi I am loading a class (Student) dynamically from a jar (samplejar.jar) file using URLClassLoader. Next thing when I want to access method or constructor of the previously loaded
No Argument Constructor Example
newInstance() method throws a NoSuchMethodException if the class does not have any
Exception Classes
- NoSuchMethodException Nonexistent method YES
Making Exceptions Unchecked - java tutorial,java tutorials
InstantiationException InterruptedException NoSuchFieldException NoSuchMethodException
Depth-first Polymorphism - tutorial
); } catch(NoSuchMethodException ex) {} cl = cl.getSuperclass

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.