49

I get 2 classes in package P. Interface class A and its implementation class B. In the file with class B I get the following error: The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files.

I'm using Eclipse Helios and

$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) Server VM (build 25.5-b02, mixed mode)

Standard solution of removing and adding JRE doesn't work. How can I fix it?

EDIT: Code:
Class A:

package com.jax;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;


@WebService
@SOAPBinding(style = Style.RPC)
public interface WebServiceInter {

@WebMethod
String sayHello();

}

Class B:

package com.jax; // **Error is here**

import javax.jws.WebService;

@WebService(endpointInterface = "com.jax.WebServiceInter")
public class WebServiceImpl implements WebServiceInter{
    @Override
    public String sayHello(){
        return "Hello!";
    }
}

Project structure: ProjectName -> Java Resources -> com.jax -> Class A, Class B

user3712116
  • 527
  • 1
  • 4
  • 8

5 Answers5

90

Java 8 supports default methods in interfaces. And in JDK 8 a lot of old interfaces now have new default methods. For example, now in CharSequence we have chars and codePoints methods.
If source level of your project is lower than 1.8, then compiler doesn't allow you to use default methods in interfaces. So it cannot compile classes that directly on indirectly depend on this interfaces.
If I get your problem right, then you have two solutions. First solution is to rollback to JDK 7, then you will use old CharSequence interface without default methods. Second solution is to set source level of your project to 1.8, then your compiler will not complain about default methods in interfaces.

mkrakhin
  • 3,386
  • 1
  • 21
  • 34
  • 3
    How can I do that? After hanging level I can't select level higher than 1.6 – user3712116 Jun 19 '14 at 09:05
  • 4
    I have not used Eclipse for a long time. But it seems that Helios doesn't support Java 8 at all. Kepler doesn't support it by default too, but there is special patch for it. Please, check [this link](https://wiki.eclipse.org/JDT/Eclipse_Java_8_Support_For_Kepler). – mkrakhin Jun 19 '14 at 09:20
  • 2
    You just saved my day. But I'm confused, doesn't this mean the java8 JRE is effectively not backward compatible? – bjorns May 08 '15 at 08:03
  • 1
    @BjörnSkoglund Well, if under backward compatibility, you mean possibility to cross-compile java code, that uses java 8 features, for java 7, then no, `javac` won't let you do this. Also, you cannot run class, compiled with JDK 8, on JVM of Java 7. And I think it's ok. The same rules applies, for example, when you try to compile code, using switch on strings, for Java 6. – mkrakhin May 08 '15 at 08:36
  • 3
    @BjörnSkoglund but usually, speaking about backward-compatibility, we mean possibility to run code compiled with old JDK on new JVM (for example, run code compiled with JDK 7 on JVM coming with Java 8). And in this case - yes, Java 8 *is* backward-compatible. – mkrakhin May 08 '15 at 08:40
  • 1
    Just to add some information about it: let's say your project is well configured with Java version X, but you run (_clean compile_) from IDE and it still fails. I had the Eclipse well configured with the default Java compiler compliance level, and the workspace and project defaults. I kept searching for some info about the compilation results with this error, and found this answer from Adobe forums: [link] (https://forums.adobe.com/thread/2334194) (check the screenshot attached). As in the screenshot, changing the Java version in JRE tab to Workspace default solved my errors when compiling. – mindOf_L Jan 17 '18 at 12:56
2

Your Eclipse software suite doesn't support Java 1.8

Download a newer version of Eclipse.

Michael Fayad
  • 1,216
  • 1
  • 17
  • 38
1

"Java 8 support for Eclipse Kepler SR2", and the new "JavaSE-1.8" execution environment showed up automatically.

Download this one:- Eclipse kepler SR2

and then follow this link:- Eclipse_Java_8_Support_For_Kepler

akshay_rahar
  • 1,661
  • 2
  • 18
  • 20
0

Make your Project and Workspace to point to JDK7 which will resolve the issue. https://developers.google.com/eclipse/docs/jdk_compliance has given ways to modify Compliance and Facet level changes.

0

Just trying to compile with ant, Have same error when using org.eclipse.jdt.core-3.5.2.v_981_R35x.jar, Everything is well after upgrade to org.eclipse.jdt.core_3.10.2.v20150120-1634.jar

Henry Li
  • 1
  • 2