The error I get when I hover over scan.useDelimiter("\n");
is: "The type java.util.regex.Pattern cannot be resolved. It is indirectly referenced from required .class files"
当我悬停在scan.useDelimiter(“\n”)时,我得到的错误;是:“java.util.regex类型。模式无法解决。它是间接引用需要的。类文件"
I have tried re-installing my Java and JDK. JRE system library jre8 is referenced in the Java build path of my project. It's the workspace' default jre. It has rt.jar in it, which I am told, should contain all I need.
我已经尝试重新安装我的Java和JDK。JRE系统库jre8在我的项目的Java构建路径中被引用。它是工作空间的默认jre。它有一个罐子,我被告知,它应该包含我所需要的一切。
When I hit run I get "Exception in thread "main" java.lang.Error: Unresolved compilation problem: at pack.Main.main(Main.java:15)
"
当我点击run时,我得到了“线程”main“java.lang”中的“异常”。错误:未解决的编译问题:在package .main .main(Main.java:15)
Line 15 only says public static void main(String[] args) {
The code with the error is in the main class, not in the main method though.
第15行仅表示公共静态void main(String[] args){该错误的代码在主类中,而不是main方法。
My goal with this piece of code is to read user input, all of it until user hits enter. The delimiter part is there because on default scan.next() stops at spaces, I want the entire line.
我的这段代码的目标是读取用户输入,直到用户点击进入。分隔符部分在那里,因为在默认情况下。next()在空格处停止,我想要整个行。
Yes, I have cleaned my project.
是的,我已经清理了我的项目。
Eclipse version: Indigo Service Release 2 Build id: 20120216-1857
Eclipse版本:Indigo Service Release 2 Build id: 20120216-1857。
Some code:
一些代码:
import java.util.Scanner;
import java.util.regex.*;
private static void someMethod(){
Scanner scan = new Scanner(System.in);
scan.useDelimiter("\n");
String pass = scan.next();
}
What is my next step here?
我的下一步是什么?
EDIT: I'm getting a comparible error when using .contrains(String) on a String: The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
编辑:当使用.contrains(String)在字符串上时,我得到了一个可比较的错误:类型java.lang。CharSequence进行不能解决。它间接地引用了所需的.class文件。
String test = "bla_bla";
if(test.contains("a_"))
1 个解决方案
#1
4
I had the same issue using JDK 1.8.0_20 and Eclipse 4.4.0. Eclipse kept saying "The import java.util.regex.Pattern cannot be resolved". This also wasn't happening in JDK 7 and 6. From my estimation, there must be something wrong with the package in JDK 8. I've also had the same issue with javax.swing.JTable with JDK 8, but not 7 or 6, so it must be JDK 8.
我使用JDK 1.8.0_20和Eclipse 4.4.0有相同的问题。Eclipse一直在说“导入java.util.regex”。模式无法解决”。这在JDK 7和6中也没有发生。根据我的估计,JDK 8中的包肯定有问题。我对javax.swing也有同样的问题。JTable与JDK 8,但不是7或6,所以它必须是JDK 8。
To solve the issue, I went to find a .jar file of the Util package that would contain a working Pattern class. After downloading one from http://www.java2s.com/Code/Jar/r/Downloadregexjar.htm, and incorporating it into my build path, Pattern once again worked. The same solution also solved my issue with the Swing package.
为了解决这个问题,我找到了一个包含工作模式类的Util包的.jar文件。在从http://www.java2s.com/Code/Jar/r/Downloadregexjar.htm下载一个文件后,将其合并到我的构建路径中,模式再次生效。同样的解决方案也用Swing包解决了我的问题。
This is not the ideal solution, as the .jar file contains a lot of redundant packages already included in JDK 1.8.0_20, but it was the only solution I could come up, besides downgrading to JDK 7 or 6.
这并不是理想的解决方案,因为.jar文件包含了许多已经包含在JDK 1.8.0_20中的冗余包,但它是我能够提出的唯一解决方案,除了对JDK 7或6进行降级。
I do hope Oracle does fix this issue soon in future releases of JDK 8.
我希望Oracle能够在JDK 8的未来版本中尽快解决这个问题。
Hope this helps!
希望这可以帮助!
#1
4
I had the same issue using JDK 1.8.0_20 and Eclipse 4.4.0. Eclipse kept saying "The import java.util.regex.Pattern cannot be resolved". This also wasn't happening in JDK 7 and 6. From my estimation, there must be something wrong with the package in JDK 8. I've also had the same issue with javax.swing.JTable with JDK 8, but not 7 or 6, so it must be JDK 8.
我使用JDK 1.8.0_20和Eclipse 4.4.0有相同的问题。Eclipse一直在说“导入java.util.regex”。模式无法解决”。这在JDK 7和6中也没有发生。根据我的估计,JDK 8中的包肯定有问题。我对javax.swing也有同样的问题。JTable与JDK 8,但不是7或6,所以它必须是JDK 8。
To solve the issue, I went to find a .jar file of the Util package that would contain a working Pattern class. After downloading one from http://www.java2s.com/Code/Jar/r/Downloadregexjar.htm, and incorporating it into my build path, Pattern once again worked. The same solution also solved my issue with the Swing package.
为了解决这个问题,我找到了一个包含工作模式类的Util包的.jar文件。在从http://www.java2s.com/Code/Jar/r/Downloadregexjar.htm下载一个文件后,将其合并到我的构建路径中,模式再次生效。同样的解决方案也用Swing包解决了我的问题。
This is not the ideal solution, as the .jar file contains a lot of redundant packages already included in JDK 1.8.0_20, but it was the only solution I could come up, besides downgrading to JDK 7 or 6.
这并不是理想的解决方案,因为.jar文件包含了许多已经包含在JDK 1.8.0_20中的冗余包,但它是我能够提出的唯一解决方案,除了对JDK 7或6进行降级。
I do hope Oracle does fix this issue soon in future releases of JDK 8.
我希望Oracle能够在JDK 8的未来版本中尽快解决这个问题。
Hope this helps!
希望这可以帮助!