简体   繁体   中英

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 . I have a .class file called 'RandomGenerator.class' which I want to instantiate from the main. The main.java and RandomGenerator.class are in the same directory.

My statement:

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

will have an error : RandomGenerator could not be resolved to a type java(16777218)

I tried to include 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.

The specification of the constructor given is RandomGenerator​(int seed, double lambda, double mu, double rho)

Appreciate help to make it work in Visual Studio Code. Thanks.

  1. Make sure RandomGenerator.class is on your path!
  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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM