NoSuchMethodException

NoSuchMethodException

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 Tutorials/Questions & Answers:
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
Advertisements
No Argument Constructor Example
newInstance() method throws a NoSuchMethodException if the class does not have any
Exception handling in java
. InterruptedException IIIegalAccessException. NoSuchMethodException. Checked.... NoSuchMethodException NOtSuchMethodException is displayed when we have
Exception Classes
- NoSuchMethodException Nonexistent method
Making Exceptions Unchecked - java tutorial,java tutorials
NoSuchMethodException Handling Exception in Java In java exception

Ads