Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / February 2005

Tip: Looking for answers? Try searching our database.

Help: incomparable types: boolean and char error in code

Thread view: 
Donna - 08 Feb 2005 20:32 GMT
I need help. I have compiled the code as listed below but get the error
message:
    incomparable types: boolean and char
   [javac]          while (continuing == '0')           {

public class Results
{
   private static String version =
       "Module Results (version Exercise 1-4)";

   static Group myGroup = new Group();

   public static void main(String args[])
   {
    char selection;
       String myNumber = "0490011";
       Student thisStudent;
       boolean continuing;

        continuing = true;
        while (continuing == '1')           {

       selection = IO.readChar
           (version + "\n\nPlease input \n1. To display all student
results\nor\n2. To display results for Student 0490011");
       switch (selection)

       {
           case '1':
               myGroup.displayAll();
               break;
           case '2':
               thisStudent = myGroup.findThisStudent(myNumber);
               thisStudent.display();
               break;
            case '3':
                continuing = false;
                break;
           default:
               IO.display (version,
                   "You didn't select 1, 2 or 3");

      }
      }
       System.exit(0);
   }
}

It appears to me that it is a stupid error but the more I look at it the
less I see.

Help me with this one please.

Many thanks,

Donna
Carl - 08 Feb 2005 20:37 GMT
> I need help. I have compiled the code as listed below but get the error
> message:
[quoted text clipped - 52 lines]
>
> Donna

I think by (continuing == '1') you mean (continuing == true) and by
(continuing == '0') you mean to say (continuing == false).

In a while loop, you can simply write while(continuing) which will be
true as long as continuing is true.

Hth,
Carl.
Boudewijn Dijkstra - 10 Feb 2005 12:30 GMT
>I need help. I have compiled the code as listed below but get the error
> message:
>     incomparable types: boolean and char
>    [javac]          while (continuing == '0')           {

The facts:
- continuing is a boolean variable
- '0' is a char literal for the decimal number zero
- == compares two expressions and returns the result as a boolean
The problem here is, that boolean and char do not allow themselves to be
compared.  In other words, continuing can never have the value '0', because it
is a boolean, not a char variable.

> public class Results
> {
[quoted text clipped - 47 lines]
>
> Donna


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.