【问题标题】:Import not working in Netbeans JAVA 8.1 Cannot find symbol导入在 Netbeans JAVA 8.1 中不起作用找不到符号
【发布时间】:2016-06-07 21:02:54
【问题描述】:

JAVA 和 Netbeans 新手

我的问题是当我尝试从另一个类调用方法时出现错误: “找不到符号”

我确实在调用类中有导入,并尝试了我能想到的所有变体,但同样的错误仍在继续。

我将方法复制到调用类中,错误消失了,但这没有用,因为很多类都需要调用这个函数。

具体如下:

在以下位置创建了一个测试方法:

计算器 |--源码包 |--schmidtjts.com.calculators |--Functions_Conversion.java

package schmidtjts.com.calculators;

public class Functions_Conversion {
        public static int test_lf(int Input) {
        return Input * 10;
    }
)

然后尝试调用它:

计算器 |--源码包 |--schmidtjts.com.calculators.ui.pages |--Displacement.java

package schmidtjts.com.calculators.ui.pages;

import schmidtjts.com.calculators.Functions_Conversion;

public class Displacement extends javax.swing.JPanel {
    public Displacement() {
        initComponents();
    }

    private void testMethod() { 
        double ttt = test_lf(1);  
    }
}

我希望有人能有一个想法,我已经搜索了许多类似描述的问题,但没有找到解决方案。 尝试删除缓存并重新启动 Netbeans。

【问题讨论】:

  • "test_lf" 是找不到的符号/方法。
  • 请寻找对象。这样,您可以随时调用该方法。

标签: java class netbeans import symbols


【解决方案1】:

更新: 您的代码应如下所示:

package schmidtjts.com.calculators.ui.pages;

//This import below isn't that relevant.
import schmidtjts.com.calculators.Functions_Conversion;

public class Displacement extends javax.swing.JPanel {
    public Displacement() {
        initComponents();
    }

    private void testMethod() { 
         //Initialize an object that can be used to call the method 
         Functions_Conversion myObject = new Functions_Conversion();

        //Then call the method using the object you've just created
         myObject.test_If(1);  
    }
}

原始答案:

尝试像这样初始化一个对象

//Initialize an object that can be used to call the method 
Functions_Conversion myObject = new Functions_Conversion();

//Then call the method using the object you've just created
myObject.test_If(1);

【讨论】:

  • 感谢您的有趣建议。不幸的是,“test_If”仍然带有红色下划线,并带有错误“找不到符号。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-22
  • 1970-01-01
相关资源
最近更新 更多