while(matcher.find()) - 错误 - 不起作用

时间:2015-07-23 06:40:32

标签: java android while-loop pattern-matching runtime-error

我需要帮助

当我有字符串“3 * 3”

时,我不知道为什么它会在matcher.find()中跳跃

代码:

    public void delSin_Cos_Tan()
            {
                o = new ArrayList<>();
                String aDate = "3*3";
                Pattern datePattern = Pattern.compile("((sin|cos|tan|sinh|cosh|tanh|asin|acos|atan)\\((.+)\\))"); 
//Operat.Sin_Cos_Tan.Patter = ((sin|cos|tan|sinh|cosh|tanh|asin|acos|atan)\((.+)\))
                Matcher matcher = datePattern.matcher(aDate);
                Log.d(TAG,"Sin Startz");
                Log.d(TAG,"Sin " + Aufgabe);
                while (matcher.find());
                {
                    Log.e(TAG,matcher.group(1)); // there is the Error, but withe the String "3*3" an i don't konw why it is jump inside the while  
                    String Gesammt = matcher.group(1);
                    String TYP = matcher.group(2);
                    String Inklammer = matcher.group(3);

                    Log.d(TAG, String.valueOf("------------------------"));
                    Log.d(TAG, Gesammt);
                    Log.d(TAG, Inklammer);
                    Log.d(TAG, TYP);
                    Log.d(TAG, String.valueOf("------------------------"));
               }
            }

我的完全代码:http://pastebin.com/jWN1ghfz

1 个答案:

答案 0 :(得分:2)

你的while循环后得到;。 这就是为什么你的完整块将永远执行!

while (matcher.find());应为while (matcher.find())(无;

这是因为

while (matcher.find());
{
 //...
}

相同
while (matcher.find()){
;
}

{
 //...
}