• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String replaceAll function error

 
Michael L. Zhang
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a small test program, but when I compile it I got an error.



Can someone tell me why I got compliling error?

javac TestReplace.java

TestReplace.java:8: cannot resolve symbol
symbol : method replaceAll (java.lang.String,java.lang.String)
location: class java.lang.String
String xyz = str.replaceAll("a","b");
^
1 error
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you using a version of jave earlier than 1.4?

also, when you do get it to compile, it won't run - main() is wrong
 
Michael L. Zhang
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My java version "1.3.1_14"

The issue with main(), You mean I should use

public static void main(String{} args), right?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael L. Zhang:
... The issue with main(), You mean I should use
public static void main(String{} args), right?

public static void main(String[] args)
 
jiju ka
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static void main(String[] args) is the right one.
But that is not your compilation issue.

Your compilation issue is not in code. The Issue is String.replaceAll method is not in your java library.

See the documentation for 1.3

http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html

replaceAll(String, String) is not defined but in jdk 1.4 and 1.5 it is present
[ January 06, 2006: Message edited by: jiju ka ]
 
Michael L. Zhang
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks every one!

I just joined the new company, and I assumed my java version is 1.4 or later, but it turned out it is not the case.

Will talk to company admin to upgrade the java.
 
Paul Clapham
Sheriff
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if your company is not upgrading yet for some reason, then you could use the char versionwhich does exist in Java 1.3. Note that you can only replace one char by another with this method, nothing more complex than that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic