1

I have the following class signature:

public BlockstemRequester(RateLimiter throttler, 
                    String url, List<String> payloadsToBeRequested, List<String> objRef) {
.
.
.
}

And I'm using that constructor at this following code:

threads.add(new BlockstemRequester(RateLimiter.create(1.0),
              String.format("url...", apiKey), 
              chunks.get(index), 
              chunksObjRef.get(index)))

where:

  • RateLimiter is from import com.google.common.util.concurrent.RateLimiter
  • chunks is defined as val chunks:util.List[util.List[String]] = new util.Vector[util.List[String]]
  • chunksObjRef is defined as val chunksObjRef:util.List[util.List[String]] = new util.Vector[util.List[String]]

But, unfortunately I'm getting an error telling me that class constructor was not found or defined:

java.lang.NoSuchMethodError: BlockstemRequester.<init>(Lcom/google/common/util/concurrent/RateLimiter;Ljava/lang/String;Ljava/util/List;Ljava/util/List;)

Basically, I'm using this class defined in Scala at my java code project, and I did defined the scala class to use List from java to avoid any problem of incompatible types between the languages.

At runtime I'm getting this following types according to my debug process:

  • chunks is a Vector[Collections$SynchronizedRandomAccessList]
  • chunksObjRef is a Vector[Collections$SynchronizedRandomAccessList]

I appreciate any kind of help towards this problem. Thank you!

0

3 Answers 3

3

Just solved the problem. So this was the scenario: I have a project X and using a library Y. So both X and Y have different definition of the class BlockstemRequester, both with different constructor signatures. I had to change that class name of my project and refactor my code. So, at runtime the constructor pointed out it was that one from my project X and not from that one defined in the library Y

I appreciate any advise if there is any way to approach this problem better than just renaming/refactoring my local classes

Sign up to request clarification or add additional context in comments.

1 Comment

No. You simply shouldn't have conflicting classes like this. OSGi and the upcoming Java 9 module system can help, but only if the classes are private to the module.
2

As per Java docs:

Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.

From you question it is not clear if you are getting this at compile time or run time but looks like you are having issue at run time. So, use a Java decompiler and check the .class of this class whether this method is present or not.

Most probable root cause of this issue is that library used at compile time have such a method but library used at runtime doesn't have it, and hence NoSuchMethodError.

Use decompiler and check .class file of the class.

7 Comments

You just wrote an essay on "NoSuchMethodError" with some misdirecting information (such as: "Use decomputer and check .class file for the class" and stuff about library- where original post clearly says the method is regarding one of the classes user implemented.)
@tanjir That's where my doubt is because he would have got the error in IDE .. I am expecting some issue with library or .class file version mis-match ..
@pjj I'm getting that at runtime and yes, I got that error on IDE at runtime
@pjj I used an online decompiler to upload the jar where is that class BlockstemRequester. But just got .java files. In the correspondent java file I found the method with the right signature.
@pjj I used an online decompiler to upload the .class file of BlockstemRequester and the signature was there
|
0

I think that the problem is with your 'typed' list.

If you change the signature to

public BlockstemRequester(RateLimiter throttler, 
       String url, List payloadsToBeRequested, List objRef) 

Or

public BlockstemRequester(RateLimiter throttler, 
       String url, List<?> payloadsToBeRequested, List<?> objRef) 

This will work.

1 Comment

Another option could be to cast payloadsToBeRequested and objRef to List<String>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.