This discussion is archived
5 Replies Latest reply: Apr 3, 2007 5:31 PM by 807599 RSS

java:56: cannot find symbol error in refrence to 'substring'???

807599 Newbie
Currently Being Moderated
I've written a program for a school assignment that (should) reads from a text file line by line and formats the data it receives. The method listed below is called upon to find a 7 character chunk of data in the string and then return it. Every time I compile the program I get this error:
---------------------------------------------------------------
NWSFB05.java:56: cannot find symbol
symbol : method substring(java.lang.String,java.lang.String)
location: class java.lang.String
     strOut = StationWeather.substring(getPos(strAlt), getPos(strAlt)+7) + " ";
______________________^
1 error
----------------------------------------------------------------


This may be a stupid question but I'm new to java and I could not find an answer on the forums that had been previously posted. Any help would be great ^_^

Code:
public String getAltWea(String strAlt)

  {

    String strOut = "";

    /** Extracts the seven character string from Station Weather
    Adds a space on the end so that we can easily work with the string */
    
      strOut = StationWeather.substring(getPos(strAlt), getPos(strAlt)+7) + " ";

    /** We are looking for the end of the Altitude Weather and then
    we pad the end with more spaces */
    strOut = strOut.substring(0,strOut.indexOf(" ",0)) + "       ";

    /** Now chop the thing down to EXACTLY seven spaces */
    strOut = strOut.substring(0,7);

    return strOut;

  } 
  • 1. Re: java:56: cannot find symbol error in refrence to 'substring'???
    807599 Newbie
    Currently Being Moderated
    public String getAltWea(String strAlt)
     
      {
     
        String strOut = "";
     
        /** Extracts the seven character string from Station Weather
        Adds a space on the end so that we can easily work with the string */
        
          strOut = StationWeather.substring(getPos(strAlt), getPos(strAlt)+7) + " ";
             //Possible error here^^ Isn't StationWeather a class?
             // If it is, does it contain a new version of the method substring?
    
             //If you haven't designed a new method substring, then a string
             //needs to be placed in front of the dot(.)
    
             // If you have defined a new substring method, are you passing
             // the method the correct amount of parameters?
    
        /** We are looking for the end of the Altitude Weather and then
        we pad the end with more spaces */
        strOut = strOut.substring(0,strOut.indexOf(" ",0)) + "       ";
     
        /** Now chop the thing down to EXACTLY seven spaces */
        strOut = strOut.substring(0,7);
     
        return strOut;
     
      } 
  • 2. Re: java:56: cannot find symbol error in refrence to 'substring'???
    796365 Newbie
    Currently Being Moderated
    It's important that you learn to interpret error messages and diagnose them.

    NWSFB05.java:56: cannot find symbol
    symbol : method substring(java.lang.String,java.lang.String)

    The compiler is telling you it doesn't recognize the method I put in bold. That means you need to check the documentation for the String class. When you do (please do so, now) you'll find that there is not a method substring that takes Strings as arguments - but that there is one that takes ints.

    So you are using strings when you should be using ints.
  • 3. Re: java:56: cannot find symbol error in refrence to 'substring'???
    807599 Newbie
    Currently Being Moderated
    I can see how that would look confusing. StationWeather should be strStationWeather (haven't renamed it properly in the program yet to follow standard formatting), it is a 70 character string that would look like this for example:
    "FAT 3111 3107+12 3106+07 3310+00 3018-15 3020-28 272443 252252 244049 "
  • 4. Re: java:56: cannot find symbol error in refrence to 'substring'???
    807599 Newbie
    Currently Being Moderated
    Well in that case, I'd read ChuckBling's reply. I believe he answered it quite nicely.
  • 5. Re: java:56: cannot find symbol error in refrence to 'substring'???
    807599 Newbie
    Currently Being Moderated
    Thanks ChuckBling after reading the documentation I see you are quite right...Now I just have to figure out how to make it work with ints haha.