Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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-01-2007, 06:52 PM
Member
 
Join Date: Dec 2007
Posts: 2
fatnic388 is on a distinguished road
'Incompatible operand' fault
Hi. I'm new to Java but been programming for a few years. Mainly PHP (Quite a few similarities between the two). I'm copying an example form a book.
Code:
char symbol; while (diskScanner.hasNext()) { symbol = diskScanner.findInLine(".").charAt(0); while (symbol != "@") { diskWriter.print(symbol); symbol = diskScanner.findInLine(".").charAt(0); } diskScanner.nextLine(); diskWriter.println(); }
The 'symbol !="@"' part is throwing 'Incompatible operand types char and String'. Not sure why, as symbol has been declared as a char and "@" is a char!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-01-2007, 08:19 PM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Use single quotes:
Code:
while (symbol != '@') {
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-01-2007, 08:32 PM
Member
 
Join Date: Dec 2007
Posts: 2
fatnic388 is on a distinguished road
Wow! That was easy! Seems like there's some basics I need to get the hang of.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-01-2007, 09:05 PM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
Yes:
Code:
diskScanner.findInLine(".").charAt(0)
That will return a single character (the char at index 0). Dont forget that chars are a primitive data type (like int, double, float, etc).
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
Error: incompatible types, found: int required: boolean silvia New To Java 6 10-08-2008 10:09 AM
Incompatible magic value 1008821359 willemjav Java Applets 2 03-21-2008 11:41 AM
problem with scanner class:incompatible types fred New To Java 1 07-20-2007 09:02 AM


All times are GMT +3. The time now is 04:38 AM.


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