StringTokenizer undefined?

Discussion in 'Java' started by Sean Washington, Sep 10, 2006.

  1. I could have swore I was doing everything right, but no matter what I
    try I end up getting the following error:

    Exception in thread "main" java.lang.Error: Unresolved compilation
    problem:
    The constructor StringTokenizer(String, String) is undefined

    at StringTokenizer.main(StringTokenizer.java:8)

    Here is my code:

    import java.util.*;

    public class StringTokenizer
    {
    public static void main(String[] Args)
    {
    String ssn = "123-34-7948";
    StringTokenizer ssnToken = new StringTokenizer(ssn, "-");
    }
    }

    What's am I doing wrong?
    Sean Washington, Sep 10, 2006
    #1
    1. Advertising

  2. Sean Washington wrote:
    > I could have swore I was doing everything right, but no matter what I
    > try I end up getting the following error:
    >
    > Exception in thread "main" java.lang.Error: Unresolved compilation
    > problem:
    > The constructor StringTokenizer(String, String) is undefined
    >
    > at StringTokenizer.main(StringTokenizer.java:8)
    >
    > Here is my code:
    >
    > import java.util.*;
    >
    > public class StringTokenizer
    > {
    > public static void main(String[] Args)
    > {
    > String ssn = "123-34-7948";
    > StringTokenizer ssnToken = new StringTokenizer(ssn, "-");
    > }
    > }
    >
    > What's am I doing wrong?


    Not defining a constructor for StringTokenizer. Of, if you want to
    construct a java.util.StringTokenizer, you need to say so, because you've
    asked to construct an instance of *your* StringTokenizer class. You'd need
    to say

    java.util.StringTokenizer ssnToken = new java.util.StringTokenizer(ssn,
    "-");


    The simplest fix is to call your class something else.
    Mike Schilling, Sep 10, 2006
    #2
    1. Advertising

  3. Sean Washington

    hiwa Guest

    Sean Washington ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:

    > I could have swore I was doing everything right, but no matter what I
    > try I end up getting the following error:
    >
    > Exception in thread "main" java.lang.Error: Unresolved compilation
    > problem:
    > The constructor StringTokenizer(String, String) is undefined
    >
    > at StringTokenizer.main(StringTokenizer.java:8)
    >
    > Here is my code:
    >
    > import java.util.*;
    >
    > public class StringTokenizer
    > {
    > public static void main(String[] Args)
    > {
    > String ssn = "123-34-7948";
    > StringTokenizer ssnToken = new StringTokenizer(ssn, "-");
    > }
    > }
    >
    > What's am I doing wrong?

    Your class name is fatally wrong.
    It hides *real* StringTokenizer.
    hiwa, Sep 10, 2006
    #3
  4. Mike Schilling wrote:
    > Sean Washington wrote:
    > > I could have swore I was doing everything right, but no matter what I
    > > try I end up getting the following error:
    > >
    > > Exception in thread "main" java.lang.Error: Unresolved compilation
    > > problem:
    > > The constructor StringTokenizer(String, String) is undefined
    > >
    > > at StringTokenizer.main(StringTokenizer.java:8)
    > >
    > > Here is my code:
    > >
    > > import java.util.*;
    > >
    > > public class StringTokenizer
    > > {
    > > public static void main(String[] Args)
    > > {
    > > String ssn = "123-34-7948";
    > > StringTokenizer ssnToken = new StringTokenizer(ssn, "-");
    > > }
    > > }
    > >
    > > What's am I doing wrong?

    >
    > Not defining a constructor for StringTokenizer. Of, if you want to
    > construct a java.util.StringTokenizer, you need to say so, because you've
    > asked to construct an instance of *your* StringTokenizer class. You'd need
    > to say
    >
    > java.util.StringTokenizer ssnToken = new java.util.StringTokenizer(ssn,
    > "-");
    >
    >
    > The simplest fix is to call your class something else.


    Im still really new to programming and my java 1 class is online so I
    may be confusing myself here... the class name is ssnToken, correct? I
    tried adding the java.util onto the StringTokenizer, but that did not
    work. I use eclipse as my IDE and it tells me there error is on the new
    'StringTokenizer(ssn, "-");' part of the line. It says: The constructor
    StringTokenizer(String, String) is undefined
    Sean Washington, Sep 10, 2006
    #4
  5. Sean Washington

    hiwa Guest

    Sean Washington ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:

    > Mike Schilling wrote:
    > > Sean Washington wrote:
    > > > I could have swore I was doing everything right, but no matter what I
    > > > try I end up getting the following error:
    > > >
    > > > Exception in thread "main" java.lang.Error: Unresolved compilation
    > > > problem:
    > > > The constructor StringTokenizer(String, String) is undefined
    > > >
    > > > at StringTokenizer.main(StringTokenizer.java:8)
    > > >
    > > > Here is my code:
    > > >
    > > > import java.util.*;
    > > >
    > > > public class StringTokenizer
    > > > {
    > > > public static void main(String[] Args)
    > > > {
    > > > String ssn = "123-34-7948";
    > > > StringTokenizer ssnToken = new StringTokenizer(ssn, "-");
    > > > }
    > > > }
    > > >
    > > > What's am I doing wrong?

    > >
    > > Not defining a constructor for StringTokenizer. Of, if you want to
    > > construct a java.util.StringTokenizer, you need to say so, because you've
    > > asked to construct an instance of *your* StringTokenizer class. You'd need
    > > to say
    > >
    > > java.util.StringTokenizer ssnToken = new java.util.StringTokenizer(ssn,
    > > "-");
    > >
    > >
    > > The simplest fix is to call your class something else.

    >
    > Im still really new to programming and my java 1 class is online so I
    > may be confusing myself here... the class name is ssnToken, correct? I
    > tried adding the java.util onto the StringTokenizer, but that did not
    > work. I use eclipse as my IDE and it tells me there error is on the new
    > 'StringTokenizer(ssn, "-");' part of the line. It says: The constructor
    > StringTokenizer(String, String) is undefined


    > public class StringTokenizer
    > {

    The cause of the error is you using the name of a Java core API class,
    which is, or happens to be, StringTokenizer. Rename your class. How
    about public class SeanWashington. The error should go away.
    hiwa, Sep 10, 2006
    #5
  6. hiwa wrote:
    > Sean Washington ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:
    >
    > > Mike Schilling wrote:
    > > > Sean Washington wrote:
    > > > > I could have swore I was doing everything right, but no matter what I
    > > > > try I end up getting the following error:
    > > > >
    > > > > Exception in thread "main" java.lang.Error: Unresolved compilation
    > > > > problem:
    > > > > The constructor StringTokenizer(String, String) is undefined
    > > > >
    > > > > at StringTokenizer.main(StringTokenizer.java:8)
    > > > >
    > > > > Here is my code:
    > > > >
    > > > > import java.util.*;
    > > > >
    > > > > public class StringTokenizer
    > > > > {
    > > > > public static void main(String[] Args)
    > > > > {
    > > > > String ssn = "123-34-7948";
    > > > > StringTokenizer ssnToken = new StringTokenizer(ssn, "-");
    > > > > }
    > > > > }
    > > > >
    > > > > What's am I doing wrong?
    > > >
    > > > Not defining a constructor for StringTokenizer. Of, if you want to
    > > > construct a java.util.StringTokenizer, you need to say so, because you've
    > > > asked to construct an instance of *your* StringTokenizer class. You'd need
    > > > to say
    > > >
    > > > java.util.StringTokenizer ssnToken = new java.util.StringTokenizer(ssn,
    > > > "-");
    > > >
    > > >
    > > > The simplest fix is to call your class something else.

    > >
    > > Im still really new to programming and my java 1 class is online so I
    > > may be confusing myself here... the class name is ssnToken, correct? I
    > > tried adding the java.util onto the StringTokenizer, but that did not
    > > work. I use eclipse as my IDE and it tells me there error is on the new
    > > 'StringTokenizer(ssn, "-");' part of the line. It says: The constructor
    > > StringTokenizer(String, String) is undefined

    >
    > > public class StringTokenizer
    > > {

    > The cause of the error is you using the name of a Java core API class,
    > which is, or happens to be, StringTokenizer. Rename your class. How
    > about public class SeanWashington. The error should go away.


    wow...I think maybe I need to go to bed.

    That worked. Thanks for the help
    Sean Washington, Sep 10, 2006
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil Hanna

    Re: StringTokenizer Help

    Phil Hanna, Jul 1, 2003, in forum: Java
    Replies:
    0
    Views:
    862
    Phil Hanna
    Jul 1, 2003
  2. ARMANDO  PADILLA

    StringTokenizer help

    ARMANDO PADILLA, Jul 4, 2003, in forum: Java
    Replies:
    3
    Views:
    605
    Chris Smith
    Jul 4, 2003
  3. Liang Yew
    Replies:
    3
    Views:
    635
    Jacob
    Jul 21, 2003
  4. Jim Crowell

    StringTokenizer Question?

    Jim Crowell, Aug 20, 2003, in forum: Java
    Replies:
    9
    Views:
    3,746
    Roedy Green
    Aug 23, 2003
  5. Newbie
    Replies:
    4
    Views:
    1,444
    Stefan Siegl
    Dec 7, 2003
Loading...

Share This Page