Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2007, 09:48 PM
Member
 
Join Date: Dec 2007
Location: Philly
Posts: 3
sondratheloser is on a distinguished road
Send a message via AIM to sondratheloser
Cannot convert from char to String error
Still working on my hangman program from yesterday (Thanks Shoeninja for help!)

I re-did a bunch of it to include global variables and such

here is the method I am still having problems with:
BuildWord is a global string variable with the value " " (8 spaces). the loop compares your 1-char guess with all 8 characters of a randomly chosen 8-letter word. What buildword does is keep track of the word you've guessed so far. So say the word is aardvark, and you guess "a" I want buildword set to "aa a ", using cnt from the for loop to replace the appropriate spaces.

"String tempword = BuildWord.charAt(cnt)" is where I am getting the cannot convert from char to string error.

Code:
public static void compare () {//BEGIN COMPARISON BuildWord=" "; for (int cnt=0;cnt <=7; cnt++) {//begin for String templetter = guessedletter; String tempword = BuildWord.charAt(cnt) //compares your one character guess to every character of the wordchosen if (guessedletter.charAt(0) == wordchosen.charAt(cnt)) { tempword = templetter; } else wrongt++; }//end for
thanks,

-Sondra
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-13-2007, 10:28 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
Code:
String tempword = BuildWord.charAt(cnt)
You are trying to assign a character to a string variable. (And you seem to forget ; at the end of the statement.)

Try this:

Code:
String tempword = (new Character(BuildWord.charAt(cnt))).toString();
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert a string into a BigInteger valery New To Java 1 08-06-2007 09:36 PM
Char to String in java trill New To Java 1 08-01-2007 02:42 PM
Help with, String, Char lenny New To Java 1 07-25-2007 03:58 PM
Error: convert from String to long bbq New To Java 1 06-29-2007 08:23 PM
How can i insert a char into a string Jamie New To Java 2 05-20-2007 10:01 PM


All times are GMT +3. The time now is 05:55 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org