This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes incomparable types: boolean and null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "incomparable types: boolean and null" Watch "incomparable types: boolean and null" New topic
Author

incomparable types: boolean and null

Ariana Abrenica
Greenhorn

Joined: Jan 06, 2012
Posts: 12
Can someone help me? Because I have never encountered this error before.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1508
    
    5

Mismatch in the data type being compared.


Swastik
Ariana Abrenica
Greenhorn

Joined: Jan 06, 2012
Posts: 12
Swastik Dey wrote:What is the error?

in line 10 it says incomparable type: boolean and null
while (read == in.readLine()!=null) and it points in "!"
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1508
    
    5

while((read = in.readLine())!=null)
Ariana Abrenica
Greenhorn

Joined: Jan 06, 2012
Posts: 12
Swastik Dey wrote:while((read = in.readLine())!=null)

thank you
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43933
    
  33
The reason is the = operator has a lower precedence than ==. You want to read the line first, then check whether it is null, so you need to make the = be evaluated before the == with the additional pair of round brackets ().
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: incomparable types: boolean and null
 
It's not a secret anymore!