Java变量可能尚未初始化? [英] Java variable might not have been initialized?

查看:162
本文介绍了Java变量可能尚未初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试编译类时,我的BlueJ IDE显示此错误。我看不出我做错了什么。



解决方案

在if块中使用变量之前,需要对其进行初始化。 / p>

试试这个:

  double albedo = 0; 

而不是:

 双反照率; 

请记住,如果您的条件返回false,您的变量将保持为0,因为您未指定一个其他区块。


My BlueJ IDE is showing this error when I try to compile the class. I can't see what I'm doing wrong.

解决方案

Before you can use a variable inside your if block , you need to initialize it.

Try this :

double albedo=0;

Instead of :

double albedo;

Keep in mind though that your variable will remain 0 if your condition returns false as you haven't specified an else block.

这篇关于Java变量可能尚未初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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