我有一个名为 Ullman
的 jar 库。该 jar 包含 1 个名为 ullman
的类。我尝试从该类访问 void,当我刚刚运行该程序时,它可以正常工作,但是当我尝试清理并构建时,出现以下错误:
error: match(ArrayList<int[][]>,int[][],ArrayList<ArrayList<String>>,ArrayList<String>,ArrayList<Integer>) is not public in Ullman; cannot be accessed from outside package
u.match(matrixgraph, matrixq, nodegraph, nodequery, nocandidategraph);
这是我导入该类的代码:
import ullman.Ullman;
public class Gui extends javax.swing.JFrame {
int max_frag;
int ratio;
public Ullman u=new Ullman();
........
然后当我尝试从这个 GUI 类访问 void 时出现错误 调用void时的示例代码
u=new Ullman();
u.match(matrixgraph, matrixq, nodegraph, nodequery, nocandidategraph);
如何修复它?
以下是ullman
类中的match
方法:
public void match(ArrayList<int[][]> matrixgraph, int[][] matrixquery, ArrayList<ArrayList<String>> nodegraph, ArrayList<String> nodequery, ArrayList<Integer> nocandidate) {
answer.clear();
matrixq=matrixquery;
for (int i = 0; i < matrixgraph.size(); i++) {
int [][]matrixsmile=matrixgraph.get(i);
matrixg=new int[matrixsmile.length-1][matrixsmile.length-1];
for(int x=0;x<matrixg.length;x++){
for(int y=0;y<matrixg.length;y++){
matrixg[x][y]=matrixsmile[x][y];
}
}
matrix_query_graph = new int[matrixq.length][matrixg[0].length];
for (int j = 0; j < matrix_query_graph.length; j++) {
for (int k = 0; k < matrix_query_graph[0].length; k++) {
matrix_query_graph[j][k] = 0;
}
}
// adjacency matrix M
ArrayList<String>nodeq = nodequery;
ArrayList<String>nodeg = nodegraph.get(i);
for(int m=0;m<nodeq.size();m++){
for(int n=0;n<nodeg.size();n++){
if (nodeq.get(m).equals(nodeg.get(n))) {
matrix_query_graph[m][n] = 1;
}
}
}
if (subgraphMatching(matrixq, matrixg, matrix_query_graph)) {
answer.add(nocandidate.get(i));
}
}
}
最佳答案
您的错误是说您尝试访问的方法在导入的类中不是公开的。
error: match(ArrayList<int[][]>,int[][],ArrayList<ArrayList<String>>,ArrayList<String>,ArrayList<Integer>) is not public in Ullman; cannot be accessed from outside package
u.match(matrixgraph, matrixq, nodegraph, nodequery, nocandidategraph);
错误清楚地表明该方法无法在 Ullman 包之外访问
因此,将 Ullman
包中的 match()
方法公开,然后您就可以访问它了。
关于java - 错误: *void is not public in *class; cannot be accessed error from outside package,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30870709/