469,358 Members | 1,626 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

incomparable types: int and <nulltype>

1
Expand|Select|Wrap|Line Numbers
  1. class Search
  2. {
  3.     public static void main (String[] args)
  4.     {
  5.         int position;
  6.         int counter = 0;    
  7.         String para;    
  8.  
  9.         para = Keyin.inString("insert a paragraph");    
  10.  
  11.         do {    
  12.         position = para.indexOf(' ');
  13.         para = para.substring ( position + 1, para.length () -1); 
  14.         counter = counter + 1;
  15.         } while ( position != null ) ;
  16.  
  17.         counter = counter + 1 ;
  18.         System.out.println(counter);
  19.             }
  20.         }
  21.  
aw well the debug says :

incomparable types: int and <nulltype>
} while ( position != null ) ;
^

HEHE any suggestions :P
Oct 15 '07 #1
3 19241
pbmods
5,821 Expert 4TB
Heya, vakon. Welcome to TSDN!

Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).

Please use CODE tags when posting source code:

[CODE=java]
Java code goes here.
[/CODE]
Oct 15 '07 #2
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1. class Search
  2. {
  3.     public static void main (String[] args)
  4.     {
  5.         int position;
  6.         int counter = 0;    
  7.         String para;    
  8.  
  9.         para = Keyin.inString("insert a paragraph");    
  10.  
  11.         do {    
  12.         position = para.indexOf(' ');
  13.         para = para.substring ( position + 1, para.length () -1); 
  14.         counter = counter + 1;
  15.         } while ( position != null ) ;
  16.  
  17.         counter = counter + 1 ;
  18.         System.out.println(counter);
  19.             }
  20.         }
  21.  
aw well the debug says :

incomparable types: int and <nulltype>
} while ( position != null ) ;
^

HEHE any suggestions :P
As the error message says, you cannot compare an int (primitive) with null (reference type).
Perhaps you want to compare position with zero?
Oct 15 '07 #3
Hi,
Change primitive type "int" to reference type "Integer".
Aug 28 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by John Dibling | last post: by
5 posts views Thread by Andy Skypeck | last post: by
8 posts views Thread by Shailesh | last post: by
188 posts views Thread by infobahn | last post: by
5 posts views Thread by Zach | last post: by
58 posts views Thread by jacob navia | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.