Class.forname throws Arrayindexoutofboundexception when trying to create object in Spring Boot application

huangapple go评论74阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年10月6日 12:48:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/64219524.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定