1

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"

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.

When I hit run I get "Exception in thread "main" java.lang.Error: Unresolved compilation problem: at pack.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.

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.

Yes, I have cleaned my project.

Eclipse version: 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

String test = "bla_bla";
if(test.contains("a_"))
GWigWam
  • 2,013
  • 4
  • 28
  • 34

1 Answers1

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.

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.

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.

I do hope Oracle does fix this issue soon in future releases of JDK 8.

Hope this helps!

Sorin Markov
  • 59
  • 1
  • 7
  • I doubt that this is a problem with Oracle Java. It is far more likely to be an Eclipse problem. – Stephen C Nov 11 '14 at 02:58
  • Thank you for the reply, it's quite a while back I ran into this problem and I have forgotten how I solved it, probably with some workaround like you. – GWigWam Nov 11 '14 at 11:06
  • @StephenC You might be right, never actually considered that. I never tried using Eclipse Kepler to see if it would fix the issue. From what I gather, its the only other version of Eclipse officially supporting Java 8. Might very well be something wrong with Eclipse Luna. I'll have to give it a try at work and see if downgrading Eclipse to Kepler will work. Thanks for that. – Sorin Markov Nov 12 '14 at 06:01