Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy Forums > > >

"cannot find symbol" Java


(!)

Baronwyn's Avatar
Computer Specs
Member with 9 posts.
THREAD STARTER
 
Join Date: Jul 2012
Experience: Beginner
08-Jul-2012, 01:03 AM #1
Question "cannot find symbol" Java
PC Win 7 64-bit system working in jGRASP. I'm relatively new to programming and a rank beginner with Java. Need to ask the user for a birthdate in this specific format (mm dd yyyy) and then extract the month, day, and year separately.

My program up to this point has compiled with no problem. With the code below, it throws the "cannot find symbol" error. This part of the program is not a method within a method, it's just in main.

//Get the date of birth.
System.out.println("Please enter the renter's date of birth (mm dd yyyy): ");
birthMonth = kb.nextChar().trim().charAt(0,1);


The "kb" is the keyboard input. I'm sure the error is in charAt(0,1); but I don't know how else to extract more than one character from a line. I've roamed around the API and haven't found a solution there yet. Thanks.
Ent's Avatar
Ent   (Josiah) Ent is offline Ent is a Trusted Advisor with special permissions.
Computer Specs
Trusted Advisor with 4,876 posts.
 
Join Date: Apr 2009
Location: United Kingdom
Experience: Intermediate
08-Jul-2012, 09:44 AM #2
I'm not a Java programmer myself, so I can only give generic suggestions and anything I can glean from the documentation.

Regarding your specific problem
charAt only takes one parameter, the index, and only gives a single character.
If you wanted to extract multiple characters from a string, either run it a few times in a loop, or better use something like substring.

I'm not sure that's the core of your problem however. You're basically using one line to do two different things: get the input from the keyboard (put it all into a string variable temporarily) and then process it (working on that variable). I'd suggest making sure that each line only does one thing, just so that you can tell whether it's the charAt making itself annoying or whether there's something wrong with the keyboard input. It just makes it easier to debug things when they're split up.

Also, make sure that birthMonth is of the right type. I doubt there's a programmer on earth who hasn't tried to put the character "1" into an integer value expecting it to be 1, and spent their due period of anguish trying to work out what is wrong.
__________________
I don't read minds. Please help everyone by answering any questions and reporting on the results of any suggestions.
Our Library of Knowledge is provided for your use. Can you help to improve it?
Baronwyn's Avatar
Computer Specs
Member with 9 posts.
THREAD STARTER
 
Join Date: Jul 2012
Experience: Beginner
08-Jul-2012, 11:06 AM #3
Thanks, that gives me some more ideas to work on. Appreciate it.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


Tags
cannot find symbol, char, java

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑