English 中文(简体)
可变性或许尚未开始?
原标题:Variable might not have been initialized?

我有以下转换方案守则:

private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {

    int type, value;
    double conversion;
    String output;

    type = Integer.parseInt(conversionchoiceInput.getText());
    value = Integer.parseInt(valueInput.getText());

    if (type == 1)
    {
    conversion = inchesToCentimetres(value);
    output = value + " inches = " + Math.round(conversion) + " centimetres";
    }
    else if (type == 2)
    {

    }
    else if (type == 3)
    {

    }
    else if (type == 4)
    {

    }
    outputLabel.setText(output); 
}

它说,如果我已经知道,“可变的产出可能不会被启动”?

感谢!

问题回答

问题是,无论方案执行方式如何,都必须首先采用<代码>产出。 只是在<代码>if的道路上启动。 因此,你必须从一开始就给它一个缺省值(空洞或某种东西),或将其归入所有分支机构。

String output = "";

if (type == 1)
{
    conversion = inchesToCentimetres(value);
    output = value + " inches = " + Math.round(conversion) + " centimetres";
}
else if (type == 2)
{
    output = "";
}
else if (type == 3)
{
    output = "";
}
else if (type == 4)
{
    output = "";
}

自然,第一个选择是最好的。

If type != 1, then output isn t initialized. And even if you give output a value in each of the if branches (1, 2, 3, 4) output might not have been initialized, as if type < 1 or > 4 it still has no value.

你刚刚宣布,那里的变化不同于最初的变数。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签