Results 1 to 4 of 4
  1. #1
    fatnic388 is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default '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.
    Java 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!

  2. #2
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Use single quotes:
    Java Code:
    while (symbol != '@') {

  3. #3
    fatnic388 is offline Member
    Join Date
    Dec 2007
    Posts
    2
    Rep Power
    0

    Default

    Wow! That was easy! Seems like there's some basics I need to get the hang of.

  4. #4
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Yes:
    Java 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).

Similar Threads

  1. Replies: 6
    Last Post: 10-08-2008, 08:09 AM
  2. Incompatible magic value 1008821359
    By willemjav in forum Java Applets
    Replies: 2
    Last Post: 03-21-2008, 09:41 AM
  3. problem with scanner class:incompatible types
    By fred in forum New To Java
    Replies: 1
    Last Post: 07-20-2007, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •