如何解决:“无法解析类型 java.lang.CharSequence。它是从所需的 .class 文件间接引用的”消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26167357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix: "the type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files" message?
提问by George Gonzalez
I'm trying to use this string
我正在尝试使用这个字符串
amountStr = amountStr.replace("$", "").replace(" ", "").replace(",", "");
but I get an error message which I know I'm getting because that string I just posted is outdated. So I was wondering what would be a good updated version of that string? here is how my whole code looks like.
但是我收到一条错误消息,我知道我收到了,因为我刚刚发布的那个字符串已经过时了。所以我想知道该字符串的良好更新版本是什么?这是我的整个代码的样子。
import java.util.Scanner;
public class QuarterMachine{
/**
* Convert the input to cents.
*/
public static void main(String[] args){
// PART I INPUT SECTION (COMPLETE)
// DO NOT CHANGE THESE LINES
Scanner cin = new Scanner(System.in);
System.out.print("Part I-Enter the amount input ($ 1,572.52): ");
String amountStr = cin.nextLine();
// PLACE YOUR CODE ONLY BELOW THIS LINE
// PLACE YOUR OUTPUT IN THESE VARIABLES
// ---------- YOUR CHANGES HERE ----------------------
double amount = 0;
int quarters = 0;
//My problem is in line below
amountStr = amountStr.replace("$", "").replace(" ", "").replace(",", "");
amount = Double.parseDouble(amountStr);
quarters = (int) (amount * 100) / 25;
// PLACE YOUR CODE ONLY ABOVE THIS LINE
// PART I OUTPUT SECTION COMPLETE
System.out.printf("Amount received($%,.0f), quarters returned(%,d)%n%n",amount, quarters);
// PART II INPUT SECTION (COMPLETE)
System.out.print("Part II-Enter seconds, minutes and hours as integers: ");
int seconds = cin.nextInt();
int minutes = cin.nextInt();
int hours = cin.nextInt();
// PLACE YOUR CODE ONLY BELOW THIS LINE
// PLACE YOUR OUTPUT IN THIS VARIABLE
String result = String.format("%02d:%02d:%02d", hours, minutes, seconds);
// YOUR CODE MUST GO ABOVE THIS LINE
// PART II - OUTPUT SECTION COMPLETE
System.out.println("Result: " + result);
}
}
回答by Osman Mutlu
I think this is some kind of a bug in Eclipse. You can fix this by trying each solution written below. If one doesn't work try the next one.
我认为这是 Eclipse 中的某种错误。您可以通过尝试下面写的每个解决方案来解决这个问题。如果一个不起作用,请尝试下一个。
- Clean the project
- Delete the project and import it once again (You might need to clean the project again)
- If above doesn't work try this link http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html. You basically remove JRE Library from project and add it again to the project.
- 清理项目
- 删除项目并再次导入(您可能需要再次清理项目)
- 如果以上不起作用,请尝试此链接http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html。您基本上从项目中删除 JRE 库并将其再次添加到项目中。
Hope this helps.
希望这可以帮助。
回答by Vaibhav Panmand
Probably you will face this error after upgrading to JDK 8 as some old interfaces now have new default methods in 1.8.
升级到 JDK 8 后,您可能会遇到此错误,因为一些旧接口现在在 1.8 中有新的默认方法。
- So first verify that Your eclipse supports jdk 1.8, eclipse should be greater than or equal to 4.3.2(Eclipse Kepler SR2).
- Eclipse complains this error if source level of your project is lower than 1.8, so set source level to 1.8 then complier will not through any exception.
- Third option is, rollback to JDK 7 to use old interfaces.
- 所以首先验证你的eclipse支持jdk 1.8,eclipse应该大于等于4.3.2(Eclipse Kepler SR2)。
- 如果您的项目的源代码级别低于 1.8,Eclipse 会抱怨此错误,因此将源代码级别设置为 1.8,那么编译器将不会通过任何异常。
- 第三个选项是,回滚到 JDK 7 以使用旧接口。
Hope this will helps
希望这会有所帮助