StringTokenizer undefined?

S

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?
 
M

Mike Schilling

Sean said:
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.
 
H

hiwa

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.
 
S

Sean Washington

Mike said:
Sean said:
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
 
H

hiwa

Sean Washington ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:
Mike said:
Sean said:
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.
 
S

Sean Washington

hiwa said:
Sean Washington ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:
Mike said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top