Error while trying to use an API. java.lang.NoSuchFieldError: INSTANCE

旧时模样 提交于 2019-11-28 12:09:47
Kim Brandl

Other posts about this error seem to suggest that it's typically caused by conflicting versions of httpcore jar. i.e., an older version of httpcore on the classpath.

For more information, I'd suggest you checkout the following posts:

I know its I am replying a bit late actually I am also struggling the same problem and I found the solution by using Maven Shade plugin.

The Problem is the JAR conflict probably your project is using a different Version Of HTTPclient then your container over which your Appliaction is running.

To resolve this use the Below Maven Shade Plugin which will change the package name of HttpClient to the specified one which packaging the JAR. This will also refactor all the usage in your code.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
    <execution>
        <phase>package</phase>
        <goals>
            <goal>shade</goal>
        </goals>
        <configuration>
            <relocations>
              <relocation>
                <pattern>org.apache.http</pattern>
                <shadedPattern>org.shaded.apache.http</shadedPattern>
              </relocation>
            </relocations>
        </configuration>
    </execution>
</executions>
</plugin>

The Above sample will change HttpClient Package with org.shaded.apache.http from org.apache.http

Maven Shade will also create a fat/uber jar so your final package size get increased and will have all the classes which you have mentioned in the Dependency in POM.

If you don't want to include the all your dependency jar in your final jar then add the Scope for the Dependency as <scope>provided</scope>.

I was using intellij for both android and spring development. In my case, I accidentally chose Android sdk as the module SDK.

After choosing JDK 1.8 and rebuilding the project fixed the issue for me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!