简体   繁体   中英

Issue loading a class file from another package

I have an issue with loading classes via Class.forName(String className) when I amtrying to get a class from another package. It keeps throwing a ClassNotFoundException , even though I am fully declaring qualified (package) names as the class name.

Is there any way to load classes from another package?

Basically, what I am trying to do is load a bunch of different class files using a configuration. This isn't explicitly necessary (I'm just fooling around with code) but I would like to know if this is possible or not.

As a last note, I am fairly new to code development, having only just begun back in November, with Java as my first language.

It is totally possible. Two things to check:

  1. Use dots as separators: "java.lang.String", not "java/lang/String" or anything else
  2. Make sure the other package is loadable -- ie, it has to be on the JVM's class path.

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