我使用 Eclipse IDE 编写简单的程序
代码如下
package java_pr;
import java.io.Console;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTestHarness {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Console console = System.console();
if (console == null) {
System.err.println("No Console !!");
System.exit(1);
}
while (true) {
Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex: "));
Matcher matcher = pattern.matcher("Enter input string to search: ");
boolean found = false;
while (matcher.find()) {
console.format("I found the text" +
"\"%s\" starting at " +
"index %d and ending at index %d.%n",
matcher.group(),
matcher.start(),
matcher.end());
found = true;
}
if (!found) {
console.format("No match found.%n");
}
}
}
}
当我尝试从命令提示符运行此程序时,出现以下错误
java.lang.ClassLoader.loadClass(Unknown Source) 处的 loadClass(Unknown Source) 找不到主类:RegexTestHarness。程序将会退出。
在eclipse中运行良好