小编Thi*_*sen的帖子

未处理的异常类型:processing.org 中的 InstantiationException

我正在尝试在处理中执行一个简单的 Class.newInstance() ,但我失败了:(

编辑:如下所示,它不起作用的原因是处理将所有代码包装到一个类中,使所有声明的类成为内部类。java语言规范规定内部类的newInstance()应该传递容器类的引用,因此将newInstance的调用改为newInstance(this); 它按预期工作。

下面的代码示例抛出了 InstantiationException。

文档说有一个公共构造函数,一切都会好起来的,但可惜。

运行处理2.2.1

代码流:它填充实现接口的所有类的列表。然后我们通过 state.runnableTypes 并尝试(但失败)实例化该类型的新实例。

请帮忙?

(对笨重的状态变量表示歉意,这与更笨重的 ryo 单元测试系统有关;))

    State state;
/* It nicely finds the Wtf class and inserts that into its classes array, 
 * but when i try to instantiate a new one, whatever I try, it throws :(
 */
void setup() {
  size(1024, 768, P3D);
  noLoop(); 
//get all the classes
  state = new State();
  Class[] types = this.getClass().getDeclaredClasses();
  state.allTypes = types;

  //enumerate castable types
  for (int i = 0, l …
Run Code Online (Sandbox Code Playgroud)

java processing

5
推荐指数
1
解决办法
3365
查看次数

标签 统计

java ×1

processing ×1