gpt4 book ai didi

java - 如何从另一个类调用对象 - 无法访问

转载 作者:太空宇宙 更新时间:2023-11-04 12:45:06 25 4
gpt4 key购买 nike

我试图从与创建列表的类不同的类中调用函数列表。我的意思是

public class FUNCTION {
String fichier=null;
int nb_link_func=-1;
String fonc_nom=null;
int [] list_id=null;

public FUNCTION() {
};
};

//////////////

public class CODE {

FUNCTION [] fonctions;

public CODE (String tree_file) {
// I fill the variable list_id up, the list of functions
};
}

//////////////

public class Tree extends JTree {

CODE code=null;
private JTree tree;
String fname=null;

public Tree (String tree_file,DefaultMutableTreeNode top) {
super(top);
code=new CODE(tree_file);

fname=fonctions[1].getNom(); //This returns cannot find symbol fonctions

};
};

它返回“无法找到符号函数”有问题,但我没有找到它

最佳答案

首先通过以下方式公开函数:

public FUNCTION [] fonctions;

并更改:

fname=fonctions[1].getNom();

至:

fname=code.fonctions[1].getNom();

关于java - 如何从另一个类调用对象 - 无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36406950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com