- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个子类,它有一个在 Android 项目中抛出异常的方法。
public class Bar extends Foo {
public void method(String someClass) throws ReflectiveOperationException {
Class.forName(someClass);
}
}
我有一个基类,它的方法反射(reflect)了它自己的方法,当然可以从子类中调用这些方法。
public class Foo {
public void reflectOnMethods() {
for (Method m : this.getClass().getDeclaredMethods()) {
//do stuff with methods
}
}
}
当 Bar 调用其继承的 reflectOnMethods 时,我会看到这样的堆栈跟踪
02-05 21:58:04.461: E/AndroidRuntime(2737): java.lang.TypeNotPresentException: Type java/lang/ReflectiveOperationException not present
02-05 21:58:04.461: E/AndroidRuntime(2737): at java.lang.Class.getDeclaredMethods(Native Method)
02-05 21:58:04.461: E/AndroidRuntime(2737): at java.lang.Class.getDeclaredMethods(Class.java:703)
当我将抛出的异常从 ReflectiveOperationException
更改后,问题就消失了至 ClassNotFoundException
但是 为什么会这样??!!?
我对此感到困惑,并会查看 JDK 源代码以尝试找出答案,但我觉得很懒。
最佳答案
问题是您正尝试在 API <19 上运行代码,但 ReflectiveOperationException
是 ClassNotFoundException
、IllegalAccessException
的基类、InstantiationException
、InvocationTargetException
、NoSuchFieldException
和 NoSuchMethodException
自 API 19 以来。
如果您希望与低于 19 的 API 级别兼容,请不要在 throws 子句中使用 ReflectiveOperationException
。
public class Bar extends Foo {
public void method(String someClass) throws ClassNotFoundException {
Class.forName(someClass);
}
}
关于java - 反射方法时抛出 TypeNotPresentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28355206/
我有一个子类,它有一个在 Android 项目中抛出异常的方法。 public class Bar extends Foo { public void method(String someCl
我有一个包含 16 个模块的 android 项目。其中许多是 java 模块,有些包括注释处理。我还针对 Java 1.8,包括对 lambda 和其他 Java 8 特性的支持。 我的大部分依赖项
我有一个应用程序,其 Gradle 模块结构类似于: app - applies war common/utilities common/auth等app模块应用 WAR 插件。当部署到远程服务器时,
Crashlytics compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') 与应用程序集成,正在 nexus 7 4.4.4 上进
我已将 Maven Surefire 插件 (2.17) 添加到我们的项目中,但构建失败并出现以下错误。 Error injecting: org.apache.maven.plugin.surefi
我正在编写一个 Maven 插件,我需要知道 List 的类型哪里Person是在依赖项中定义的对象。该插件在process-classes期间运行阶段根据在宿主项目中带注释的类上找到的内容生成一些文
项目在 IntelliJ IDEA 2018.1.1 和 JDK 1.8.0_221 中成功运行当我们的新同事尝试在 IntelliJ IDEA 2019.1.1 中启动它时,他们都遇到了错误: or
我在我正在处理的 android 测试项目中设置了以下示例测试用例。 package com.whatever.test; import static org.junit.Assert.fail; i
我希望通过引用链接 http://www.adam-bien.com/roller/abien/entry/jax_rs_get_swagger_json 来创建 swagger.json 定义。我将
我有以下 pom.xml,其中包含手动 jax deps jaxb-api、jaxb-impl 和 jaxb-core 由于其从 JDK 11 中删除: org.springfram
我是 Maven 的新手,一直在尝试为一个项目创建构建。我开火时出现以下错误: mvn 全新安装 检查项目。 [INFO] --- maven-surefire-plugin:2.12.4:test
我的一个应用程序中出现了非常有趣的错误。我的应用程序在 android L 上运行良好,但是当我尝试在其他 android 版本上运行它时,我在尝试使用 Retrofit 调用 Web 服务时收到 C
我正在用 java 创建一个示例 maven 项目,当我在目标中指定测试时遇到这个异常,它给出了构建错误。但是clean , compile , test-compile工作正常。即结果成功构建但在我
我的grails应用程序中出现TypeNotPresentException。下面是Stacktrace片段 [INFO] [groovyc] java.lang.TypeNotPresentEx
我是一名优秀的程序员,十分优秀!