如下三个文件都在一个包里,但是运行报错,如下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);// 这里就不报错
}}
解决方案 »
- .do文件 要传递给servlet 而jsp文件不需要,是這樣的嗎?
- 学习Java的好的书籍是什么,请教有经验的高手
- 如果做出类似Windows Exploer打开文件夹 右边的界面
- 集合框架中元素的内存释放问题。
- 怎样选定列啊?我刚学JTable,看了些资料 + 查API还是没搞懂怎么弄,请大家帮忙啊
- swing中如何用键盘上的键(比如F1)弹出窗口?在线等,急!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 再问JTextArea+JScrollPane滚动条自动在最下边
- 大侠帮忙:用C写的socket和用java写的socket能通信吗?
- 关于一个JAVA测试问题
- 初学applet,在html里面如何显示?
- 我把MSSQL中的文件转换到MYSQL中
- 怎么解决32-bit SWT libraries on 64-bit JVM
这个变量要申明为 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 ;
};