1 Replies - 11980 Views - Last Post: 06 July 2012 - 09:47 PM Rate Topic: -----

#1 TheSourceCode   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-July 12

Why do a get a "cannot find symbol error" w/ the replaceALL me

Posted 06 July 2012 - 08:56 PM

Whenever I try the replaceALL method, I get a "cannot find symbol" error,

What am I doing wrong with my short program and how can I successfully use the replaceALL method?

This is the code that I have:


public class exp
{
    public static void main(String [] args)
    {

        String a = "Hello, Hello, Hello, Hi, Hi, Hey";

        String newA = a.replaceALL("Hello", "Bye");

    }
}


This post has been edited by macosxnerd101: 07 July 2012 - 04:29 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Why do a get a "cannot find symbol error" w/ the replaceALL me

#2 GregBrannon   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2250
  • View blog
  • Posts: 5,340
  • Joined: 10-September 10

Re: Why do a get a "cannot find symbol error" w/ the replaceALL me

Posted 06 July 2012 - 09:47 PM

Quote

What am I doing wrong with my short program and how can I successfully use the replaceALL method?

A short list of suggestions:

1. Learn to use the Java API so that you don't make these kind of mistakes or at least can recover from them on your own,

(There is no such thing as a String.replaceALL() method.)

2. Recognize and use Java naming conventions so that a misstep like replaceALL() will be recognized quickly,

(The Java naming convention for methods is that they begin with a lowercase letter and subsequent words are capitalized. Java class names begin with a capital letter then follow the same convention as for methods. Java class names should describe what the class does. Give variables names that describe what they are. Use of single-letter variable names except as array indices or loop control variables is rarely appropriate.)

3. Learn what the error messages mean so that you have an idea how to fix these simple errors (I think there's tutorial here on becoming a better debugger.)

("cannot find symbol" means you've given the compiler something it doesn't recognize - another hint that replaceALL() isn't a valid method. Unfortunately, becoming familiar with the error messages means you have to make and fix most of the them, but their meanings become clearer with experience.)

4. And when you post code here, post it between code tags.

(Instructions are in the new user FAQ and repeated on most every page you visit in the course of posting a topic.)

Keep coding!
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1