如下三个文件都在一个包里,但是运行报错,如下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);// 这里就不报错
}}

解决方案 »

  1.   

    WordSeg seg;
      这个变量要申明为 static 类型的,你的那个方法为 static
      

  2.   

    WordSeg static seg; 这样么?
      

  3.   

    WordSeg seg; 不是 static的 ,所以在 static方法里面不能调用 ,即 static修饰的方法里面只能使用static修饰的对象属性 ,非static修饰的 方法可以使用 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 ;
     };