如下三个文件都在一个包里,但是运行报错,如下WordSeg.java
public class WordSeg
{
public static void main(String[] args) throws SQLException
{
****
}
public static String Segmentation(String content) throws SQLException {
SegTag segTag = new SegTag(1);// 分词路径的数目
SegResult segResult = segTag.split(content.trim());
String classifyContent = segResult.getFinalResult();
System.out.println("分词结果\n" + classifyContent);
GetSentece(classifyContent, content);
System.out.println();
return classifyContent;
}
}Spider.javapublic class Spider
{
WordSeg seg;
public static ArrayList<String> getNodeList(String url)
{
seg.Segmentation(result.get(0)); // 这里报cannot make a static reference to the non-static field seg
}
public static void main(String[] args)
{***}
}
GUI.javapublic class GUI
{
public void actionPerformed(ActionEvent e) {
String segresult = seg.Segmentation(result);// 这里就不报错
}}
public class WordSeg
{
public static void main(String[] args) throws SQLException
{
****
}
public static String Segmentation(String content) throws SQLException {
SegTag segTag = new SegTag(1);// 分词路径的数目
SegResult segResult = segTag.split(content.trim());
String classifyContent = segResult.getFinalResult();
System.out.println("分词结果\n" + classifyContent);
GetSentece(classifyContent, content);
System.out.println();
return classifyContent;
}
}Spider.javapublic class Spider
{
WordSeg seg;
public static ArrayList<String> getNodeList(String url)
{
seg.Segmentation(result.get(0)); // 这里报cannot make a static reference to the non-static field seg
}
public static void main(String[] args)
{***}
}
GUI.javapublic class GUI
{
public void actionPerformed(ActionEvent e) {
String segresult = seg.Segmentation(result);// 这里就不报错
}}
这个变量要申明为 static 类型的,你的那个方法为 static
1、将WordSeg seg; 修改为 static WordSeg seg; 或者
1、public static ArrayList<String> getNodeList(String url)
{
seg.Segmentation(result.get(0)); // 这里报cannot make a static reference to the non-static field seg
} 修改为 :public ArrayList<String> getNodeList(String url)
{
seg.Segmentation(result.get(0)); // 这里报cannot make a static reference to the non-static field seg
}2、public void actionPerformed(ActionEvent e) {
String segresult = seg.Segmentation(result);// 这里就不报错
}
修改为:public void actionPerformed(ActionEvent e) {
String segresult = new Spider().getSe()g.Segmentation(result);// 这里就不报错
}3、为 WordSeg seg;增加
getter方法 public WordSeg getSeg(){
return this.seg ;
};