java.lang.NoSuchMethodError类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中java.lang.NoSuchMethodError类的一些代码示例,展示了NoSuchMethodError类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NoSuchMethodError类的具体详情如下:
包路径:java.lang.NoSuchMethodError
类名称:NoSuchMethodError

NoSuchMethodError介绍

[英]Thrown when the VM notices that a program tries to reference, on a class or object, a method that does not exist.
[中]当VM注意到程序试图在类或对象上引用不存在的方法时引发。

代码示例

代码示例来源:origin: wildfly/wildfly

public Constructor<T> run() {
  try {
    return clazz.getDeclaredConstructor(paramTypes);
  } catch (NoSuchMethodException e) {
    throw new NoSuchMethodError(e.getMessage());
  }
}

代码示例来源:origin: org.springframework.boot/spring-boot

private String extractClassName(NoSuchMethodError cause) {
  int descriptorIndex = cause.getMessage().indexOf('(');
  if (descriptorIndex == -1) {
    return null;
  }
  String classAndMethodName = cause.getMessage().substring(0, descriptorIndex);
  int methodNameIndex = classAndMethodName.lastIndexOf('.');
  if (methodNameIndex == -1) {
    return null;
  }
  return classAndMethodName.substring(0, methodNameIndex);
}

代码示例来源:origin: jenkinsci/jenkins

private static Method init() {
    try {
      Method m = ClassLoader.class.getDeclaredMethod("findResource", String.class);
      m.setAccessible(true);
      return m;
    } catch (NoSuchMethodException e) {
      throw (Error)new NoSuchMethodError().initCause(e);
    }
  }
}

代码示例来源:origin: wangdan/AisenWeiBo

e.printStackTrace();

代码示例来源:origin: iqiyi/Neptune

/**
 * vivo X5L, 4,4, java.lang.NoSuchMethodError: android.os.Bundle.getParcelable
 */
private static <T extends Parcelable> T getBundleParcelable(Bundle bundle, String key) {
  try {
    return bundle.getParcelable(key);
  } catch (NoSuchMethodError e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: org.mockito/mockito-core

/**
 * Returns the type of {@link ArgumentMatcher#matches(Object)} of the given
 * {@link ArgumentMatcher} implementation.
 */
private static Class<?> getArgumentType(ArgumentMatcher<?> argumentMatcher) {
  Method[] methods = argumentMatcher.getClass().getMethods();
  for (Method method : methods) {
    if (isMatchesMethod(method)) {
      return method.getParameterTypes()[0];
    }
  }
  throw new NoSuchMethodError("Method 'matches(T)' not found in ArgumentMatcher: " + argumentMatcher + " !\r\n Please file a bug with this stack trace at: https://github.com/mockito/mockito/issues/new ");
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Due to the return type change in {@link Executable} in 1.377, the caller needs a special precaution now.
 * @param e Executable
 * @return Discovered subtask
 */
public static @Nonnull SubTask getParentOf(@Nonnull Executable e) 
    throws Error, RuntimeException {
  try {
    return e.getParent();
  } catch (AbstractMethodError ignored) { // will fallback to a private implementation
    try {
      Method m = e.getClass().getMethod("getParent");
      m.setAccessible(true);
      return (SubTask) m.invoke(e);
    } catch (IllegalAccessException x) {
      throw (Error)new IllegalAccessError().initCause(x);
    } catch (NoSuchMethodException x) {
      throw (Error)new NoSuchMethodError().initCause(x);
    } catch (InvocationTargetException x) {
      Throwable y = x.getTargetException();
      if (y instanceof Error)     throw (Error)y;
      if (y instanceof RuntimeException)     throw (RuntimeException)y;
      throw new Error(x);
    }
  }
}

代码示例来源:origin: org.springframework.boot/spring-boot

private String getDescription(NoSuchMethodError cause, String className,
    List<URL> candidates, URL actual) {
  StringWriter description = new StringWriter();
  PrintWriter writer = new PrintWriter(description);
  writer.print("An attempt was made to call the method ");
  writer.print(cause.getMessage());
  writer.print(" but it does not exist. Its class, ");
  writer.print(className);
  writer.println(", is available from the following locations:");
  writer.println();
  for (URL candidate : candidates) {
    writer.print("    ");
    writer.println(candidate);
  }
  writer.println();
  writer.println("It was loaded from the following location:");
  writer.println();
  writer.print("    ");
  writer.println(actual);
  return description.toString();
}

代码示例来源:origin: wildfly/wildfly

public Constructor<OptionalDataException> run() {
    try {
      final Constructor<OptionalDataException> constructor = OptionalDataException.class.getDeclaredConstructor(boolean.class);
      constructor.setAccessible(true);
      return constructor;
    } catch (NoSuchMethodException e) {
      throw new NoSuchMethodError(e.getMessage());
    }
  }
});

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

private static <T> Constructor<T> tryGetDeclaredConstructor(Class<T> clazz) {
  try {
    return clazz.getDeclaredConstructor((Class<T>[])emptyClass);
  } catch (NoSuchMethodException e) {
    logger.log(Level.INFO,"No default constructor found on "+clazz,e);
    NoSuchMethodError exp;
    if(clazz.getDeclaringClass()!=null && !Modifier.isStatic(clazz.getModifiers())) {
      exp = new NoSuchMethodError(Messages.NO_DEFAULT_CONSTRUCTOR_IN_INNER_CLASS
                        .format(clazz.getName()));
    } else {
      exp = new NoSuchMethodError(e.getMessage());
    }
    exp.initCause(e);
    throw exp;
  }
}

代码示例来源:origin: redisson/redisson

String msg = nsme.getMessage();
if (msg != null && msg.contains("org.slf4j.impl.StaticLoggerBinder.getSingleton()")) {
  INITIALIZATION_STATE = FAILED_INITIALIZATION;

代码示例来源:origin: robovm/robovm

private static Method findCallback(Class<?> cls, String methodName) {
  for (Method m : cls.getDeclaredMethods()) {
    if (m.getName().equals(methodName)) {
      return m;
    }
  }
  throw new NoSuchMethodError(methodName);
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

exp = new NoSuchMethodError(errorMsg.getMessage());
exp.initCause(errorMsg);
throw exp;

代码示例来源:origin: wildfly/wildfly

String msg = nsme.getMessage();
if (msg != null && msg.contains("org.slf4j.impl.StaticLoggerBinder.getSingleton()")) {
  INITIALIZATION_STATE = FAILED_INITIALIZATION;

代码示例来源:origin: google/j2objc

public FastConstructor getConstructor(Class[] parameterTypes) {
  try {
    return getConstructor(type.getConstructor(parameterTypes));
  } catch (NoSuchMethodException e) {
    throw new NoSuchMethodError(e.getMessage());
  }
}

代码示例来源:origin: com.sun.xml.bind/jaxb-impl

ElementBeanInfoImpl(JAXBContextImpl grammar, RuntimeElementInfo rei) {
  super(grammar,rei,(Class<JAXBElement>)rei.getType(),true,false,true);
  this.property = PropertyFactory.create(grammar,rei.getProperty());
  tagName = rei.getElementName();
  expectedType = (Class) Utils.REFLECTION_NAVIGATOR.erasure(rei.getContentInMemoryType());
  scope = rei.getScope()==null ? JAXBElement.GlobalScope.class : rei.getScope().getClazz();
  Class type = (Class) Utils.REFLECTION_NAVIGATOR.erasure(rei.getType());
  if(type==JAXBElement.class)
    constructor = null;
  else {
    try {
      constructor = type.getConstructor(expectedType);
    } catch (NoSuchMethodException e) {
      NoSuchMethodError x = new NoSuchMethodError("Failed to find the constructor for " + type + " with " + expectedType);
      x.initCause(e);
      throw x;
    }
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void loadFromXml(Properties props, InputStream is) throws IOException {
  try {
    props.loadFromXML(is);
  }
  catch (NoSuchMethodError err) {
    throw new IOException("Cannot load properties XML file - not running on JDK 1.5+: " + err.getMessage());
  }
}

代码示例来源:origin: google/j2objc

public FastMethod getMethod(String name, Class[] parameterTypes) {
  try {
    return getMethod(type.getMethod(name, parameterTypes));
  } catch (NoSuchMethodException e) {
    throw new NoSuchMethodError(e.getMessage());
  }
}

代码示例来源:origin: org.glassfish.jaxb/jaxb-runtime

private static <T> Constructor<T> tryGetDeclaredConstructor(Class<T> clazz) {
  try {
    return clazz.getDeclaredConstructor((Class<T>[])emptyClass);
  } catch (NoSuchMethodException e) {
    logger.log(Level.INFO,"No default constructor found on "+clazz,e);
    NoSuchMethodError exp;
    if(clazz.getDeclaringClass()!=null && !Modifier.isStatic(clazz.getModifiers())) {
      exp = new NoSuchMethodError(Messages.NO_DEFAULT_CONSTRUCTOR_IN_INNER_CLASS
                        .format(clazz.getName()));
    } else {
      exp = new NoSuchMethodError(e.getMessage());
    }
    exp.initCause(e);
    throw exp;
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

public void storeToXml(Properties props, OutputStream os, String header, String encoding) throws IOException {
  try {
    props.storeToXML(os, header, encoding);
  }
  catch (NoSuchMethodError err) {
    throw new IOException("Cannot store properties XML file - not running on JDK 1.5+: " + err.getMessage());
  }
}

相关文章