Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java error: Found interface ... but class was expected

Tags:

java

guice

I am getting a strange runtime error from my code:

"Found interface [SomeInterface] but class was expected" 

How can this happen? How can an interface get instantiated?

Update: (In response to some answers) I am compiling and running against the same set of libraries, but I am using Guice to inject a Provider for this particular Interface.

The problem went away when I bound an implementation to the interface (seems like the @ImplementedBy annotation was not enough).

I was more interested in the mechanics through which Guice managed to actually instantiate an interface.

like image 294
levik Avatar asked Feb 26 '09 16:02

levik


1 Answers

This happens when your runtime classpath is different than your compile time classpath.

When your application was compiled, a class (named SomeInterface in your question) existed as a class.

When your application is running at compile time, SomeInterface exists as an interface (instead of a class.)

This causes an IncompatibleClassChangeError to be thrown at runtime.

This is a common occurence if you had a different version of a jar file on the compile time classpath than on the runtime classpath.

like image 113
Jared Avatar answered Sep 20 '22 03:09

Jared