Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

java - The operator is undefined

I just tried to make a simple class that lets me figure out the length of a file:

public class Size {

    long s = 0;
    int a;

    public static void main(String[]args){
        new Size();
    }

    Size(){

        try{
        FileInputStream str = new FileInputStream("E:/Eclipse/Resources/smile.jpg");

        while(a != null){
            s++;
        }
        }catch (IOException e){
            e.printStackTrace();
        }

    }


}

I run into a problem with

while(a != null)

I get the Error:

The operator != is undefined for the argument type(s) int, null

Any ideas why it's blocking the condition?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Primitive types in Java cannot be null. If you want to check for 0, do a != 0.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...