请查看以下代码。
String [] array=prettyHtml.split(" ");
String finalTxt="";
for(int i=0;i<array.length;i++)
{
if(previousDiff.contains(array[i]))
{
finalTxt=prettyHtml.replaceAll(array[i], "");
}
}
执行第finalTxt=prettyHtml.replaceAll(array[i], "");
行时,如果文字中有+
符号,我有时会收到以下错误消息。重要的是要注意,我并不总是得到它。
03-29 11:58:34.512: E/AndroidRuntime(27319): FATAL EXCEPTION: main
03-29 11:58:34.512: E/AndroidRuntime(27319): Process: com.phonegap.helloworld, PID: 27319
03-29 11:58:34.512: E/AndroidRuntime(27319): java.util.regex.PatternSyntaxException: Syntax error in regexp pattern near index 1:
03-29 11:58:34.512: E/AndroidRuntime(27319): +
03-29 11:58:34.512: E/AndroidRuntime(27319): ^
03-29 11:58:34.512: E/AndroidRuntime(27319): at java.util.regex.Pattern.compileImpl(Native Method)
03-29 11:58:34.512: E/AndroidRuntime(27319): at java.util.regex.Pattern.compile(Pattern.java:411)
03-29 11:58:34.512: E/AndroidRuntime(27319): at java.util.regex.Pattern.<init>(Pattern.java:394)
03-29 11:58:34.512: E/AndroidRuntime(27319): at java.util.regex.Pattern.compile(Pattern.java:381)
03-29 11:58:34.512: E/AndroidRuntime(27319): at java.lang.String.replaceAll(String.java:1785)
03-29 11:58:34.512: E/AndroidRuntime(27319): at SpeechRecPlug.receiveWhatWasHeard(SpeechRecPlug.java:436)
03-29 11:58:34.512: E/AndroidRuntime(27319): at SpeechRecPlug.access$1100(SpeechRecPlug.java:35)
03-29 11:58:34.512: E/AndroidRuntime(27319): at SpeechRecPlug$RecognitionListenerClass.onPartialResults(SpeechRecPlug.java:323)
03-29 11:58:34.512: E/AndroidRuntime(27319): at android.speech.SpeechRecognizer$InternalListener$1.handleMessage(SpeechRecognizer.java:451)
03-29 11:58:34.512: E/AndroidRuntime(27319): at android.os.Handler.dispatchMessage(Handler.java:102)
03-29 11:58:34.512: E/AndroidRuntime(27319): at android.os.Looper.loop(Looper.java:136)
03-29 11:58:34.512: E/AndroidRuntime(27319): at android.app.ActivityThread.main(ActivityThread.java:5426)
03-29 11:58:34.512: E/AndroidRuntime(27319): at java.lang.reflect.Method.invokeNative(Native Method)
03-29 11:58:34.512: E/AndroidRuntime(27319): at java.lang.reflect.Method.invoke(Method.java:515)
03-29 11:58:34.512: E/AndroidRuntime(27319): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
03-29 11:58:34.512: E/AndroidRuntime(27319): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
03-29 11:58:34.512: E/AndroidRuntime(27319): at dalvik.system.NativeStart.main(Native Method)
我该如何解决这个问题?