很有意思的问题,为什么运行没有错,调试的时候却报错!!!!

hou553403977 2012-07-31 09:26:35
public class Groups {
static public final String POEM = "I am singing o\n" + "I am dawning o\n"
+ "I am thinking o\n";

public static void main(String[] args) {

Matcher m = Pattern.compile("(?m)(\\S+)\\s+((\\S+)\\s+(\\S+))$")
.matcher(POEM);
while (m.find()) {
for (int j = 0; j <= m.groupCount(); j++) {
System.out.print("[" + m.group(j) + "]");
}
System.out.println();
}
}
}
为什么代码运行没有错,在for循环里面设断点调试的时候却报错,或者在while处设断点就进不去while循环里面,求高手解答!!!!
...全文
128 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[am singing o][am][singing o][singing][o]
[am dawning o][am][dawning o][dawning][o]
[am thinking o][am][thinking o][thinking][o]

运行正常,调试了也正常
hou553403977 2012-07-31
  • 打赏
  • 举报
回复
我调试的时候按2下f6,就进入到了Matcher.class然后就进入这个函数
public String group(int group) {
if (first < 0)
throw new IllegalStateException("No match found");
..................
hou553403977 2012-07-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

调试了下也是正常运行的啊,没报异常啊
[/Quote]
不是吧,不是就我一个人吧!!!
VanBaston 2012-07-31
  • 打赏
  • 举报
回复
调试了下也是正常运行的啊,没报异常啊
hou553403977 2012-07-31
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

正常运行
[/Quote]
我出现了IllegalStateException
hou553403977 2012-07-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

运行结果如下:
[am singing o][am][singing o][singing][o]
[am dawning o][am][dawning o][dawning][o]
[am thinking o][am][thinking o][thinking][o]
按你说的设了断点正常运行啊。。
[/Quote]
我出现了IllegalStateException
hou553403977 2012-07-31
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
public class Groups {
static public final String POEM = "I am singing o\n" + "I am dawning o\n"
+ "I am thinking o\n";

public static void main(String[] args) {

Matcher m = Pattern.compile("(?m……
[/Quote]
调试进去的时候
sffx123 2012-07-31
  • 打赏
  • 举报
回复
正常运行
ss36290109 2012-07-31
  • 打赏
  • 举报
回复
运行结果如下:
[am singing o][am][singing o][singing][o]
[am dawning o][am][dawning o][dawning][o]
[am thinking o][am][thinking o][thinking][o]
按你说的设了断点正常运行啊。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧