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 / General / March 2007

Tip: Looking for answers? Try searching our database.

another question.

Thread view: 
mmcnurlin@usfamily.net - 28 Mar 2007 03:20 GMT
The line:

while( instring = in.readLine() != null )

gives me the message:

required: java.lang.String
 while( instring = in.readLine() != null )
//  Read till null
                                 ^
FT.java:22: incompatible types
found   : java.lang.String
required: boolean
 while( instring = in.readLine() != null )
//  Read till null
                 ^
2 errors
(This a notepad capture; actually in the dos window the carat is beneath the
!= sign and then
for the 2nd error underneath the equals sign.

java -version outputs:

java version "1.5.0_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
Java HotSpot(TM) Client VM (build 1.5.0_03-b07, mixed mode, sharing)

Is it possible that java to make the authors code. Does anyone know a way to
use the readLine() method until it
reaches the end of data?
Tom Hawtin - 28 Mar 2007 03:32 GMT
> while( instring = in.readLine() != null )

It's a question of precedence. Which operator binds with its operands
more tightly. Generally it's a good idea to put parentheses where it
isn't obvious. For instance does 'a || b && c' mean '(a || b) && c' or
'a || (b && c)'? I honestly cannot remember the arbitrary rule. But that
doesn't matter because any sensible is going to put the parentheses in.

> Is it possible that java to make the authors code. Does anyone know a way to
> use the readLine() method until it
> reaches the end of data?

For clarity, I'd would separate the assignment from the condition:

    for (;;) {
        String line = in.readLine();
        if (line == null) {
            break;
        }
    }

It's more important to be clear (and compile) than to use the shortest
number of lines.

Tom Hawtin
Dan Andrews - 28 Mar 2007 03:35 GMT
On Mar 27, 8:20 pm, <mmcnur...@usfamily.net> wrote:
[snip]
> Does anyone know a way to
> use the readLine() method until it
> reaches the end of data?

Here is some reading for you:

http://www.javalobby.org/java/forums/t90743.html?start=0

In that link is my preference for reading to the end of data plus some
other good comments too.

Cheers,
Dan Andrews
-------------------
http://www.ansir.ca
Patricia Shanahan - 28 Mar 2007 03:41 GMT
> The line:
>
[quoted text clipped - 16 lines]
> != sign and then
> for the 2nd error underneath the equals sign.

while( ( instring = in.readLine() ) != null )

Patricia
Andrew Thompson - 28 Mar 2007 03:53 GMT
On Mar 28, 12:20 pm, <mmcnur...@usfamily.net> wrote:

Sub: another question.

Note that for best help, subject lines should
be specific, and not presume the reader has
knowledge of earlier posts.

A good subject line for this might be..
 (help with) incompatible types

Andrew T.


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.