简体   繁体   中英

java runtime error when loading a class

I will do my best to explain the exact situation we ran into. Let me know if you guys have additional questions. I do not know if this is a java linking issue or a java loading issue.

I have compiled the code using a external jar file which has changed during the execution. I am referencing a class file called "Contract" in my code. The library which I am using at compile time has a "Contract" class which extends from the "BaseContract" class. But the library which I am using at execution time does not have a super class ("BaseContract"). At runtime, I get aa error saying BaseContract class is not found. The class referencing the "Contract" class, lets say, is called "AppClass".

At compile time, does java store the class hierarchy of all its referenced classes in the class file which is being compiled. In my specific example, does java store the class hierarchy of the "Contract" class in the AppClass.class file? If so, why does java have to store the class hierarchy here. Is it not more efficient to store the class "Contract" hierarchy in the Contract.class file rather than in the AppClass.class file?

Any help or pointers are greatly appreciated.

No, it doesn't. Each class knows only it's own class hierarchy. However it also knows when it goes to make a method call, create an object, etc the expected signature of that method, type of that object, etc.

If nothing is available matching that expectation then you will get the class not found error (or other similar errors depending on exactly what the miss-match is).

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