关于 The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class 报错的解决方法

又开始牙疼 …看不了什么东西 ,md,The
type java.lang.CharSequence cannot be resolved. It is indirectly referenced
from required .class,前几天用myeclipse10做项目遇到的一个问题,换了jdk6就好了,也没追究根源。正好趁现在解决一下

问题描述

在这里插入图片描述

项目报错,语法没问题,类的开头有一个红色叉号。删了这个类又从另一个类里出现,当时第一天写的时候没有报错,第二天打开继续写,直接在项目旁边出现了红色叉号,莫名其妙的跑出来个这玩意弄得我很头疼,然后就随便搜了一下,直接把jdk改成myeclipse自带的1.6就解决了。

问题出现的原因

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 lowerthan 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.

大概就是说版本对不上,当时创建项目的时候我是用的JDK 1.6 ,第二天再打开时变成了自己设置的默认的JDK 1.8。

解决方法

解决方法有两种:

1.降低JDK;

2.升级IDE;

1.降低jdk

一开始使用的jdk 1.8,myeclipse 10好像用不了jdk 1.8

选择Window->Preferences。在Java下找到Installed JAEs,选择JDK 1.6 .

在这里插入图片描述

确认之后刷新一边,报错就没有了。
在这里插入图片描述

2.升级IDE

由于Myeclipse 10不支持jdk 1.8。直接换个IDE,比如eclipse、idea等等。。

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐