Results 1 to 11 of 11
  1. #1
    shihad_s is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default Error: "The method startsWith(String, String) is undefined for the type StringUtils"

    Hii,

    I got an error during compiling the below line: Error: "The method startsWith(String, String) is undefined for the type StringUtils"

    code: if (StringUtils.isBlank (line) || StringUtils.startsWith (line, "#"))

    I have imported all the required packages ( import org.apache.commons.lang.StringUtils; ..) and jars..

    Please anyone let me know what the error was..

    Thanks
    Shihad S

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by shihad_s View Post
    Hii,

    I got an error during compiling the below line: Error: "The method startsWith(String, String) is undefined for the type StringUtils"

    code: if (StringUtils.isBlank (line) || StringUtils.startsWith (line, "#"))

    I have imported all the required packages ( import org.apache.commons.lang.StringUtils; ..) and jars..

    Please anyone let me know what the error was..
    The compiler already told you: the class StringUtils doesn't have a method startsWith( ... ); check the documentation.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    shihad_s is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default Error: "The method startsWith(String, String) is undefined for the type StringUtils"

    Thanks josAH for your reply.....
    But class "StringUtils" have the method startsWith(string, string) I have checked and confirmed that..

  4. #4
    SmilingKey is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default

    hi,

    try

    String line="xxxxxxxxxxxxxxxxxxx";
    boolean result=line.startsWith("#");

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

    Default

    Correction: indeed it has; show us your code and the complete error message please.

    kind regards,

    Jos
    Last edited by JosAH; 12-07-2010 at 08:54 AM.
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    shihad_s is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    Hi josAH,

    Just check this link. It specifies the method startsWith(string, string) in the class StringUtils

    Commons Lang 2.5 API

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by shihad_s View Post
    Hi josAH,

    Just check this link. It specifies the method startsWith(string, string) in the class StringUtils

    Commons Lang 2.5 API
    Yes, I read it already; have you correctly imported the package or class?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    shihad_s is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    Hi josAH,

    Error is solved. i tried Mr. SmilingKey's suggestion..: " line.startsWith("#") ". Now it is working.. Thanks for all your replies. Expecting your co-operation in the future also..

    Thanks
    Shihad S

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,534
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by shihad_s View Post
    Hi josAH,

    Error is solved. i tried Mr. SmilingKey's suggestion..: " line.startsWith("#") ". Now it is working.. Thanks for all your replies. Expecting your co-operation in the future also..
    You 'unsolved' the problem: the String class also has a startsWith( ... ) method but now we still don't know why your original attempt didn't work; the StringUtil class also seems to implement a (static) startsWith( ... ) method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    shihad_s is offline Member
    Join Date
    Dec 2010
    Posts
    14
    Rep Power
    0

    Default

    Ya, thats right.. My actual code is given below:

    -----------------------------------------------------------

    private List<String> loadTestValues (String _resourceName) throws IOException
    {
    final InputStream testFileStream = getClass ().getClassLoader ().getResourceAsStream (_resourceName);
    List<String> lines;
    try
    {
    assertNotNull ("unable to find " + _resourceName, testFileStream);
    lines = IOUtils.readLines (testFileStream);
    }
    finally
    {
    IOUtils.closeQuietly (testFileStream);
    }
    final Iterator<String> i = lines.iterator ();
    while (i.hasNext ())
    {
    final String line = i.next ();

    if (StringUtils.isBlank (line) || StringUtils.startsWith (line, "#"))
    {
    i.remove ();
    }
    }
    return lines;
    }

    -------------------------------------------------------------------------

    Line marked in bold causes the error: "The method startsWith(String, String) is undefined for the type StringUtils". I dnt Know why the error is happening. I have imported all required packages and jar's.. Can you please try to find out that..

  11. #11
    SmilingKey is offline Member
    Join Date
    Dec 2010
    Posts
    19
    Rep Power
    0

    Default

    write "StringUtils." in you code to see if StringUtils you are using has method startsWith (String, String).

    If not, you can use:
    if (StringUtils.isBlank (line) || line.startsWith ("#"))

Similar Threads

  1. Replies: 2
    Last Post: 05-07-2010, 11:02 PM
  2. string comparison with "=" and ".equal"
    By guavajuice in forum New To Java
    Replies: 9
    Last Post: 04-22-2010, 09:01 PM
  3. jsp insert into database error(java.lang.NumberFormatException: For input string: "")
    By cypher_girl in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 12-22-2009, 03:14 AM
  4. Replies: 3
    Last Post: 05-21-2009, 03:48 PM
  5. Replies: 0
    Last Post: 04-02-2009, 07:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •