英文:
Class.forname throws Arrayindexoutofboundexception when trying to create object in Spring Boot application
问题
我正试图使用 Class.forName 方法创建一个对象,但当我调用它时,控制台显示以下异常:
> ArrayIndexOutOfBoundsException
我正在使用参数从外部路径加载一些库:
> -Dloader.path=/home/atul/ext_jars/
不太确定问题出在哪里,项目编译成功并已启动。
英文:
I am trying to create a object using Class.forname method but when I am calling it, I got the
> Arrayindexoutofboundexception
exception in the console.
I am loading few libraries from external path using argument
> -Dloader.path=/home/atul/ext_jars/
NOt sure what exactly the problem is, project compiles successfully and started.
答案1
得分: 1
我已解决了这个问题,正如我所说,我外部添加了一些库。因此,其中一个库我使用了不同的名称创建,但包含了相同名称和包的类。
所以当 Class.forname 寻找这个类时,在类路径中找到了2个类,因此抛出了与 indexoutofbound 相关的异常。
修复方法是删除包含相同类的那个jar文件。这将解决这个问题。在类路径中只需要一个包含这个类的库。
英文:
I resolve the issue, as I said I have added few libraries externally. So one of the library which I created with different name, containing same class with same name and package etc.
So when Class.forname look for the class, it found 2 classes in the classpath, so throwing the exception related to indexoutofbound.
The fix is to remove the jar which contains same class. This will fix the issue. Need only one library in classpath which contains the class.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论