运算符未定义 [英] The operator is undefined

查看:109
本文介绍了运算符未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试图制作一个简单的类,让我弄清楚文件的长度:

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();
        }

    }


}

我遇到了问题

while(a != null)

我收到错误消息:

未指定参数类型int的运算符!=,为空

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

有什么想法可以阻止这种情况吗?

Any ideas why it's blocking the condition?

推荐答案

Java中的原始类型不能为null.如果要检查0,请执行a != 0.

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

这篇关于运算符未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆