简体   繁体   English

如何使用Visual Studio Code在Java .class中实例化一个类?

[英]How to instantiate a class in a Java .class using Visual Studio Code?

I am using Visual Studio Code (version 1.32.3) with Java . 我正在使用Visual Studio Code (version 1.32.3)Java I have a .class file called 'RandomGenerator.class' which I want to instantiate from the main. 我有一个名为'RandomGenerator.class'的.class文件,我想从main实例化。 The main.java and RandomGenerator.class are in the same directory. main.java和RandomGenerator.class位于同一目录中。

My statement: 我的声明:

RandomGenerator rdgen = new RandomGenerator(1,1,1,1);

will have an error : RandomGenerator could not be resolved to a type java(16777218) 将出现错误: RandomGenerator could not be resolved to a type java(16777218)

I tried to include import RandomGenerator; 我试图包含import RandomGenerator; (I don't need but try to see if it is required) - I get an error "RandomGenerator cannot be resolved java(268435846)" at the import statement. (我不需要但是试着看看是否需要) - 我在import语句中得到一个错误"RandomGenerator cannot be resolved java(268435846)"

The specification of the constructor given is RandomGenerator​(int seed, double lambda, double mu, double rho) 给定的构造函数的规范是RandomGenerator​(int seed, double lambda, double mu, double rho)

Appreciate help to make it work in Visual Studio Code. 感谢帮助使其在Visual Studio Code中运行。 Thanks. 谢谢。

  1. Make sure RandomGenerator.class is on your path! 确保RandomGenerator.class在您的路径上!
  2. Import the class in the file that is using it! 在使用它的文件中导入该类!

If that does not work - is RandomGenerator visible or your class, ie public or package private and in the same package? 如果这不起作用 - RandomGenerator是可见的还是您的类,即公共或包私有并且在同一个包中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 这个Java代码如何实例化一个抽象类? - How does this Java code instantiate an abstract class? 如何在 Visual Studio Code 中使用 java.class 文件? - How to use java .class file in Visual Studio Code? 如何在Java中实例化一个抽象类? - How to instantiate an abstract class in Java? 如何在Java中为visual studio代码修复“错误:在应用程序类路径上找到的类:Main” - How to fix "error: class found on application class path: Main" in java for visual studio code 如何在Java中实例化Socket类? - How to instantiate a Socket class in Java? 如何实例化抽象类的内部类-Java - How to instantiate inner class of abstract class - java 如何在Android Studio中使用扩展类的构造函数和方法'getDeclaredConstructor'实例化具有类类型的类 - How to Instantiate a class with the class type, using constructor of extended class with method 'getDeclaredConstructor', in Android Studio 如何使用反射实例化具有泛型类的java.util.ArrayList - How To Instantiate a java.util.ArrayList with Generic Class Using Reflection 如何禁用运行 | Visual Studio 代码中 java 主 class 文件中的调试选项 - How do i disable Run | Debug option coming in java main class file in Visual Studio code 使用反射实例化一个匿名 Java 类 - Instantiate an anonymous Java class using reflection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM