java--met Nosuchmethoderror general solution idea

Source: Internet
Author: User

Recently took over the new project, the project a run, Nosuchmethoderror jumped out, finally solved, for a computer, Nosuchmethoderror again jumped out, simply, summed up the nosuchmethoderror should be how to deal with the idea.

With the following general idea, you can solve this error without having to know the business situation.

Below is a demonstration of how to deal with this error in the event of knowing nothing:

  Find a random error example :

Caused By:java.lang.Nosuchmethoderror: Org.eclipse.jdt.internal.compiler.compiler.<init> (lorg/eclipse/jdt/internal/compiler/env/ Inameenvironment; Lorg/eclipse/jdt/internal/compiler/ierrorhandlingpolicy; Lorg/eclipse/jdt/internal/compiler/impl/compileroptions; Lorg/eclipse/jdt/internal/compiler/icompilerrequestor; lorg/eclipse/jdt/internal/compiler/iproblemfactory;) V at Com.taobao.sketch.compile.Compiler.generateClass (Compiler.java:392) at Com.taobao.sketch.compile.Compiler.compile (Compiler.java:38) at Com.taobao.sketch.compile.SketchCompilationContext.globalVmCompile (Sketchcompilationcontext.java:403) at Com.taobao.sketch.runtime.SketchRuntimeServer.getGlobalVmTemplate (Sketchruntimeserver.java:622) at Com.taobao.sketch.runtime.SketchRuntimeServer.resolveGloabalVm (Sketchruntimeserver.java:136) at Com.taobao.sketch.runtime.SketchRuntimeServer.initializeVmLibrary (Sketchruntimeserver.java:127) at Com.taobao.sketch.runtime.SketchRuntimeServer.init (Sketchruntimeserver.java:96) at Com.taobao.sketch.SketchEngine.init (Sketchengine.java:66) at Com.taobao.sketch.service.impl.SketchEngineImpl.init (Sketchengineimpl.java:118) at Com.alibaba.citrus.springext.support.BeanSupport.afterPropertiesSet (Beansupport.java:80) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods ( Abstractautowirecapablebeanfactory.java:1369) at Org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean ( Abstractautowirecapablebeanfactory.java:1335)    ... More

This is a WEBX framework under the Javaweb project, at the start of the jetty server times error. At the beginning to see the error, the heart is dashed, just take over the project, the previous code is not my writing, how I know will not find the method is what causes the AH. Don't worry, just look at the possible cause of the error.

  possible causes of errors :

    1. There's this class, and the class really doesn't have this method
    2. There was this class, and there were several, and they clashed.

  cause exclusion :

  1, click on the code to enter the error line, in the error place hit a debug Point, re-start the project or reproduce the error, let the program run to the line code:

     

    

  2. Open the display interface (if not, find the interface in Window--show view),

Manual knocking out Xxx.class.getProtectionDomain (). Getcodesource (), XXX is the full class name of the error class, the mouse selects the line code, click on the top right corner of the screen J icon, will print out To the address of the package where the class corresponds.  As shown in.

As you can see, the result is:

(Java.security.CodeSource) (FILE:/D:/PROGRAM%20FILES%20 (x86)/eclipse/configuration/org.eclipse.osgi/843/0/.cp/ Lib/core-3.1.1.jar <no signer certificates>)

  3. Then copy the class name, shortcut key ctrl+shift+t Open The open type interface, view our project references to the package, which has this class:

  

We found that there are two org.eclipse.jdt.internal.compiler.Compiler in this class, namely:

Package One: Ecj.3.5.1.jar

Package Two:Core-3.1.1.jar

The addresses were:

  

But we found that just in the display , we see that the address is actually not from the above two addresses (the address of the two packets above are in the C Drive,DEBUG Package from the D -disk, that is, the package that implements the runtime environment is not configured in our own project, because open typy can only find what is in its own project.

So, where is this package of D -disk introduced?

Think, this error is in the project start times, then in addition to the project, and "Server" may introduce other packages, then it is possible that the server to help us to introduce it?

  4 , open the server's Classpath , you can find that the server did introduce this package

  

So we "Remove" The package from the classpath of the server.

  5 , restart the project again, Dubug , card points, Display , this time the results are as follows:

  Found: In the actual environment, now has not introduced the D - disk that core-3.1.1.jar package. We let the project run, and we find that the same mistake was reported-no method was found. Then we'll let the project cite Ecj.3.5.1.jar This package to try.

  6 , ctrl+shift+t , double-click Enter Core-3.1.1.jar in Compiler the directory structure in which the class resides:

   

Tip: On the left column, tick this flag to expand the directory where the package is located:

  

  

Similarly, open The directory structure where the Compiler class resides in Ecj.3.5.1.jar.

Finally found that this jar All packages are under the same project, and two packages have The compiler class, preceded by core-3.1.1.jar core-3.1.1.jar compiler so error . But eclipse When looking for a class, as long as the order to find one, will not look down, So the ecj-3.5.1.jar will not be found, Even if there is compiler This class, and there is the method we want.

  7 , exclude Core-3.1.1.jar Package:

The project is a MAVEN project. We tried to search for core directly in the Pom.xml of the project and the package was not searchable, so this core-3.1.1 The package may be due to the introduction of other projects in the project, and other projects introduced Core-3.1.1.jar, so this project indirectly brought the package.

Also, because the project is a maven project, you can exclude this package by using the following method:

  

After exclusion, the pom.xml of the project becomes:

  

If it is a non-MAVEN project, you can either drop the package directly from Lib, or open the. classpath file from underneath the project root to find the corresponding package configuration and delete the row.

With this pom.xml We can see that there are two of jar Packet collisions for the following reasons:

1,   this project a ecj-3.5.1.jar package, with the introduction of the project b while project b introduced Core-3.1.1.jar, so this project is also the equivalent of introducing core-3.1.1.jar This is the maven in the project jar

2,   why maven There's no automatic fix for us jar ecj-3.5.1.jar package and core-3.1.1.jar package groupid and artifactid maven > think this is two jar as above. exclusions exclude. So when we develop a component, the name is a very important problem, if the upgrade component even the name is changed, users will be very inconvenient.

Start the project again and solve the problem.

java--met Nosuchmethoderror general solution idea

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.