Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

incomparable types: boolean and null

 
Ariana Abrenica
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me? Because I have never encountered this error before.
 
Swastik Dey
Rancher
Posts: 1604
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mismatch in the data type being compared.
 
Ariana Abrenica
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1604
5
Android Java Java ME
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
while((read = in.readLine())!=null)
 
Ariana Abrenica
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swastik Dey wrote:while((read = in.readLine())!=null)

thank you
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic