Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

StringTokenizer undefined?

Thread view: 
Sean Washington - 10 Sep 2006 05:14 GMT
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?
Mike Schilling - 10 Sep 2006 05:17 GMT
> I could have swore I was doing everything right, but no matter what I
> try I end up getting the following error:
[quoted text clipped - 19 lines]
>
> 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.
Sean Washington - 10 Sep 2006 05:29 GMT
> > I could have swore I was doing everything right, but no matter what I
> > try I end up getting the following error:
[quoted text clipped - 29 lines]
>
> 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
hiwa - 10 Sep 2006 05:39 GMT
Sean Washington のメッセージ:

> > > I could have swore I was doing everything right, but no matter what I
> > > try I end up getting the following error:
[quoted text clipped - 36 lines]
> '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.
Sean Washington - 10 Sep 2006 05:47 GMT
> Sean Washington のメッセージ:
>
[quoted text clipped - 44 lines]
> 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
hiwa - 10 Sep 2006 05:19 GMT
Sean Washington のメッセージ:

> I could have swore I was doing everything right, but no matter what I
> try I end up getting the following error:
[quoted text clipped - 19 lines]
>
> What's am I doing wrong?
Your class name is fatally wrong.
It hides *real* StringTokenizer.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.