Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 反射加载一个类的对象,并将该对象作为另一个类的新线程运行_Java_Multithreading_Reflection - Fatal编程技术网

Java 反射加载一个类的对象,并将该对象作为另一个类的新线程运行

Java 反射加载一个类的对象,并将该对象作为另一个类的新线程运行,java,multithreading,reflection,Java,Multithreading,Reflection,我已经用Java学习反射了几天了 我有两个类,SimulatorInstance和SimulatorInstanceThread。我正在尝试使用反射加载SimulatorInstance实例,并使用SimulatorInstanceThread中的Runnable接口将该对象作为新线程运行 我已尝试使用Classloader加载SimulatorInstance类: ClassLoader simInstance=SimulatorInstance.class.getClassLoader()

我已经用Java学习反射了几天了

我有两个类,SimulatorInstance和SimulatorInstanceThread。我正在尝试使用反射加载SimulatorInstance实例,并使用SimulatorInstanceThread中的Runnable接口将该对象作为新线程运行

我已尝试使用Classloader加载SimulatorInstance类:

ClassLoader simInstance=SimulatorInstance.class.getClassLoader()


并尝试将其作为新线程运行。但它不起作用。我知道这可能是非常基本的。但是有人能指出这里的错误是什么吗?

“不起作用”没有给出任何提示。你提供的信息有限,很难说问题出在哪里。您能提供您的类的详细信息、错误消息等吗?

如果我理解您的意图,您就得到了类加载器,但我认为这是不正确的。让我们看一看如何更好地理解如何创建通过反射找到的类。所以,我试着把它铸造成runnable。但我得到了一个演员例外@约哈内斯