Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.NoSuchMethodError:Graph:method<;初始化>;()找不到_Java_Linux_Eclipse_Command Line - Fatal编程技术网

java.lang.NoSuchMethodError:Graph:method<;初始化>;()找不到

java.lang.NoSuchMethodError:Graph:method<;初始化>;()找不到,java,linux,eclipse,command-line,Java,Linux,Eclipse,Command Line,我在eclipse中遇到了一个令人困惑的错误,但在我们的主服务器上却没有从命令行linux帐户中得到。所有代码都在eclipse中的主src目录中。代码在命令行编译,但在Mac OS X笔记本电脑上的Eclipse中产生以下错误: Exception in thread "main" java.lang.NoSuchMethodError: Graph: method <init>()V not found at Lab17.main(Lab17.java:11) Grap

我在eclipse中遇到了一个令人困惑的错误,但在我们的主服务器上却没有从命令行linux帐户中得到。所有代码都在eclipse中的主src目录中。代码在命令行编译,但在Mac OS X笔记本电脑上的Eclipse中产生以下错误:

Exception in thread "main" java.lang.NoSuchMethodError: Graph: method <init>()V not found
    at Lab17.main(Lab17.java:11)
Graph.java

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
public class Lab17 {

// Lab17 first attempt at creating a graph

    public static void main(String[] args) throws Exception {

        Graph myGraph = new Graph();

        URLConnection conn = null;
        try {
            URL url = new URL("http://csc.mendocino.edu/~jbergamini/222data/flights/flights");
            conn = url.openConnection();
        } catch (IOException e) {
            System.out.println("Unable to open Flights file");
            System.exit(1);
        }
        Scanner s = null;
        try {
            s = new Scanner(conn.getInputStream());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        while (s.hasNext()) {
            String src = s.next();
            String dst = s.next();
            s.next();
            double cost = s.nextDouble();
            //System.out.println(src+" "+dst+" "+cost);
            myGraph.addEdge(src, dst, cost);
        }

        System.out.println(myGraph.breadthFirst("Austin", "Washington"));    
        System.out.println(myGraph.depthFirst("LosAngeles", "Washington"));
        System.out.println(myGraph.breadthFirst("LosAngeles", "Washington"));
        System.out.println(myGraph.depthFirst("Washington", "LosAngeles"));
        System.out.println(myGraph.breadthFirst("Washington", "LosAngeles"));

    }

}
import java.util.LinkedList;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.TreeMap;

public class Graph {

    private TreeMap<String, Vertex> vertexMap;

    /** Creates a new, empty graph */
    public Graph() {
        // create vertexMap for Graph
        vertexMap = new TreeMap<String, Vertex>();

    }

    /**
     * Adds an edge
     * @param src the source vertex
     * @param dst the destination vertex
     * @param cost the weight of the edge
     */
    public void addEdge(String src, String dst, double cost) {
        //System.out.println(src+" "+dst+" "+cost+" in Graph()");
        // check to see if there is a src vertex
        if(vertexMap.get(src) == null) {
            // if src Vertex does not exist create Vertex for src
            vertexMap.put(src, (new Vertex(src)));
            //System.out.println(vertexMap.get(src).toString());
        }

        // check to see if there is a dst Vertex
        if(vertexMap.get(dst) == null) {
            // if dst Vertex does not exist create Vertex for dst
            vertexMap.put(dst, (new Vertex(dst)));
            //System.out.println(vertexMap.get(dst).toString());
        }

        // populate the dst and cost for Edge on the src Vertex vertexMap element 
        Vertex srdVertex = vertexMap.get(src);
        Vertex dstVertex = vertexMap.get(dst);
        Edge sEdge = new Edge(dstVertex, cost);
        srdVertex.addEdge(sEdge);
    }

    /** Clears/empties the graph */
    public void clear() {
        vertexMap = new TreeMap<String,Vertex>();
    }

    /**
     * Traverses, depth-first, from src to dst, and prints the vertex names in the order visited.
     * @param src the source vertex
     * @param dst the destination vertex
     * @return whether a path exists from src to dst
     */
    public boolean depthFirst(String src, String dst) {
        System.out.println("Depth-first from "+src+" to "+dst);
        for(Map.Entry<String,Vertex> entry: vertexMap.entrySet()) {
            String key = entry.getKey();
            Vertex thisVertex = entry.getValue();

            System.out.println(key + " => " + thisVertex.toString());
        }
        return false;
    }

    /**
     * Traverses, breadth-first, from src to dst, and prints the vertex names in the order visited
     * @param src the source vertex
     * @param dst the destination vertex
     * @return whether a path exists from src to dst
     */
    public boolean breadthFirst(String src, String dst) {
        System.out.println("Breadth-first from "+src+" to "+dst);
        // find starting vertex in vertexMap
        Vertex start = vertexMap.get(src);
        LinkedList<Vertex> vertexQue = new LinkedList<Vertex>();
        LinkedList<Vertex> visitedV = new LinkedList<Vertex>();
        // check it for null
        if( start == null) {
            throw new NoSuchElementException(" Start vertex not found");
        }

        // create a Queue for searching through vertex edges
        //Queue<Vertex> q = new Queue<Vertex>();
        vertexQue.add( start );
        start.dest = 0;
        boolean found = false;
        while( !vertexQue.isEmpty() && !found) {
            Vertex v = vertexQue.removeLast();
            if( v.toString() == dst) {
                // print queue
                found = true;
            }
            else if(!visitedV.contains(v)){
                // put all the adj vertex's into the queue
                for( Edge e: v.getEdges() ) {
                    Vertex w = e.getDst();
                    vertexQue.add( w );
                }
            }
            // add v to visitedV linked list

            if(!visitedV.contains(v)){
                visitedV.add(v);
            }
        }

        System.out.print("[");
        for(int i=0; i < visitedV.size(); i++) {
            System.out.print(visitedV.get(i)+", ");
        }
        System.out.println("]");

        /*forVertex> entry: vertexMap.entrySet()) {
            String key = entry.getKey();
            Vertex thisVertex = entry.getValue();

            System.out.println(key + " => " + thisVertex.toString());

            for(Edge e : thisVertex.getEdges() ){
                System.out.print(e.toString());
            }
            System.out.println();
            System.out.println("All Edges Evaluated");
        }*/
        return false;
    }
}
import java.util.Set;
import java.util.TreeSet;

public class Vertex {

  private String name;
  private TreeSet<Edge> adj;
  public double dest;

  /**
   * Creates a new vertex
   * @param name the name of the vertex
   */
  public Vertex(String name) {
    this.name = name;
    adj = new TreeSet<Edge>();
  }

  public TreeSet<Edge> getEdges() {
      return this.adj;
  }

  /**
   * Returns the set of all edges starting from this vertex.
   * Set shall be ordered with respect to the names of the destination vertices.
   */
  public Set<Edge> allAdjacent() {
      Set<Edge> vertexSet = adj;

      return null;
  }

  public String toString() {

    return name;
  }

  public void addEdge(Edge e) {

      this.adj.add(e);
  }
}

public class Edge implements Comparable<Edge> {

  private Vertex dst;
  private double cost;

  /** Creates a new edge with an associated cost
   * @param dst the destination vertex
   * @param cost the weight of the edge
   */
  public Edge(Vertex dst, double cost) {
    this.dst = dst;
    this.cost = cost;
  }

  public Vertex getDst() {
      return dst;
  }

  @Override
  public int compareTo(Edge o)
  {
      if(o == null)
          return -1;
      if(this == null)
          return -1;
      if( this.dst.toString().compareTo( ((Edge)o).dst.toString() ) == 0 )
          return 0;
      else if ( this.dst.toString().compareTo( ((Edge)o).dst.toString() ) < 0 )
          return 1;
      else 
          return -1;
  }

  public String toString() {
        String theEdgeS = this.dst.toString()+" "+Double.toString(cost);
        return theEdgeS;
      }
}
import java.util.LinkedList;
导入java.util.Map;
导入java.util.NoSuchElementException;
导入java.util.TreeMap;
公共类图{
私有树映射顶点映射;
/**创建一个新的空图形*/
公共图(){
//为图形创建顶点贴图
vertexMap=新树映射();
}
/**
*添加一条边
*@param src源顶点
*@param dst目标顶点
*@param消耗了刃的重量
*/
公共无效追加(字符串src、字符串dst、双重成本){
//System.out.println(图()中的src+“”+dst+“”+cost+“”);
//检查是否存在src顶点
if(vertexMap.get(src)==null){
//如果src顶点不存在,请为src创建顶点
放置(src,(新顶点(src));
//System.out.println(vertexMap.get(src.toString());
}
//检查是否存在dst顶点
if(vertexMap.get(dst)==null){
//如果dst顶点不存在,请为dst创建顶点
放置(dst,(新顶点(dst));
//System.out.println(vertexMap.get(dst.toString());
}
//在src vertexMap元素上填充边的dst和成本
顶点srdVertex=vertexMap.get(src);
Vertex dstVertex=vertexMap.get(dst);
边缘莎草=新边缘(顶点,成本);
莎草;
}
/**清除/清空图形*/
公共空间清除(){
vertexMap=新树映射();
}
/**
*以深度优先的方式从src遍历到dst,并按访问顺序打印顶点名称。
*@param src源顶点
*@param dst目标顶点
*@return是否存在从src到dst的路径
*/
公共布尔深度优先(字符串src、字符串dst){
System.out.println(“深度优先从“+src+”到“+dst”);
对于(Map.Entry:vertexMap.entrySet()){
String key=entry.getKey();
顶点thisVertex=entry.getValue();
System.out.println(key+“=>”+thisVertex.toString());
}
返回false;
}
/**
*以宽度优先的方式从src遍历到dst,并按访问顺序打印顶点名称
*@param src源顶点
*@param dst目标顶点
*@return是否存在从src到dst的路径
*/
公共布尔值宽度优先(字符串src、字符串dst){
System.out.println(“宽度优先,从“+src+”到“+dst”);
//在vertexMap中查找起始顶点
顶点开始=vertexMap.get(src);
LinkedList vertexQue=新建LinkedList();
LinkedList visitedV=新建LinkedList();
//检查它是否为空
if(start==null){
抛出新的NoTouchElementException(“未找到起始顶点”);
}
//创建用于搜索顶点边的队列
//队列q=新队列();
顶点。添加(开始);
start.dest=0;
布尔值=false;
而(!vertexQue.isEmpty()&&!found){
Vertex v=vertexQue.removeLast();
如果(v.toString()==dst){
//打印队列
发现=真;
}
如果(!visitedV.contains(v))为else{
//将所有调整顶点放入队列
对于(边e:v.getEdges()){
顶点w=e.getDst();
顶点。添加(w);
}
}
//将v添加到visitedV链接列表
如果(!visitedV.contains(v)){
访问v.添加(v);
}
}
系统输出打印(“[”);
对于(int i=0;ientry:vertexMap.entrySet()){
String key=entry.getKey();
顶点thisVertex=entry.getValue();
System.out.println(key+“=>”+thisVertex.toString());
对于(边e:thisVertex.GetEdge()){
System.out.print(例如toString());
}
System.out.println();
System.out.println(“评估的所有边”);
}*/
返回false;
}
}
Vertex.java

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
public class Lab17 {

// Lab17 first attempt at creating a graph

    public static void main(String[] args) throws Exception {

        Graph myGraph = new Graph();

        URLConnection conn = null;
        try {
            URL url = new URL("http://csc.mendocino.edu/~jbergamini/222data/flights/flights");
            conn = url.openConnection();
        } catch (IOException e) {
            System.out.println("Unable to open Flights file");
            System.exit(1);
        }
        Scanner s = null;
        try {
            s = new Scanner(conn.getInputStream());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        while (s.hasNext()) {
            String src = s.next();
            String dst = s.next();
            s.next();
            double cost = s.nextDouble();
            //System.out.println(src+" "+dst+" "+cost);
            myGraph.addEdge(src, dst, cost);
        }

        System.out.println(myGraph.breadthFirst("Austin", "Washington"));    
        System.out.println(myGraph.depthFirst("LosAngeles", "Washington"));
        System.out.println(myGraph.breadthFirst("LosAngeles", "Washington"));
        System.out.println(myGraph.depthFirst("Washington", "LosAngeles"));
        System.out.println(myGraph.breadthFirst("Washington", "LosAngeles"));

    }

}
import java.util.LinkedList;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.TreeMap;

public class Graph {

    private TreeMap<String, Vertex> vertexMap;

    /** Creates a new, empty graph */
    public Graph() {
        // create vertexMap for Graph
        vertexMap = new TreeMap<String, Vertex>();

    }

    /**
     * Adds an edge
     * @param src the source vertex
     * @param dst the destination vertex
     * @param cost the weight of the edge
     */
    public void addEdge(String src, String dst, double cost) {
        //System.out.println(src+" "+dst+" "+cost+" in Graph()");
        // check to see if there is a src vertex
        if(vertexMap.get(src) == null) {
            // if src Vertex does not exist create Vertex for src
            vertexMap.put(src, (new Vertex(src)));
            //System.out.println(vertexMap.get(src).toString());
        }

        // check to see if there is a dst Vertex
        if(vertexMap.get(dst) == null) {
            // if dst Vertex does not exist create Vertex for dst
            vertexMap.put(dst, (new Vertex(dst)));
            //System.out.println(vertexMap.get(dst).toString());
        }

        // populate the dst and cost for Edge on the src Vertex vertexMap element 
        Vertex srdVertex = vertexMap.get(src);
        Vertex dstVertex = vertexMap.get(dst);
        Edge sEdge = new Edge(dstVertex, cost);
        srdVertex.addEdge(sEdge);
    }

    /** Clears/empties the graph */
    public void clear() {
        vertexMap = new TreeMap<String,Vertex>();
    }

    /**
     * Traverses, depth-first, from src to dst, and prints the vertex names in the order visited.
     * @param src the source vertex
     * @param dst the destination vertex
     * @return whether a path exists from src to dst
     */
    public boolean depthFirst(String src, String dst) {
        System.out.println("Depth-first from "+src+" to "+dst);
        for(Map.Entry<String,Vertex> entry: vertexMap.entrySet()) {
            String key = entry.getKey();
            Vertex thisVertex = entry.getValue();

            System.out.println(key + " => " + thisVertex.toString());
        }
        return false;
    }

    /**
     * Traverses, breadth-first, from src to dst, and prints the vertex names in the order visited
     * @param src the source vertex
     * @param dst the destination vertex
     * @return whether a path exists from src to dst
     */
    public boolean breadthFirst(String src, String dst) {
        System.out.println("Breadth-first from "+src+" to "+dst);
        // find starting vertex in vertexMap
        Vertex start = vertexMap.get(src);
        LinkedList<Vertex> vertexQue = new LinkedList<Vertex>();
        LinkedList<Vertex> visitedV = new LinkedList<Vertex>();
        // check it for null
        if( start == null) {
            throw new NoSuchElementException(" Start vertex not found");
        }

        // create a Queue for searching through vertex edges
        //Queue<Vertex> q = new Queue<Vertex>();
        vertexQue.add( start );
        start.dest = 0;
        boolean found = false;
        while( !vertexQue.isEmpty() && !found) {
            Vertex v = vertexQue.removeLast();
            if( v.toString() == dst) {
                // print queue
                found = true;
            }
            else if(!visitedV.contains(v)){
                // put all the adj vertex's into the queue
                for( Edge e: v.getEdges() ) {
                    Vertex w = e.getDst();
                    vertexQue.add( w );
                }
            }
            // add v to visitedV linked list

            if(!visitedV.contains(v)){
                visitedV.add(v);
            }
        }

        System.out.print("[");
        for(int i=0; i < visitedV.size(); i++) {
            System.out.print(visitedV.get(i)+", ");
        }
        System.out.println("]");

        /*forVertex> entry: vertexMap.entrySet()) {
            String key = entry.getKey();
            Vertex thisVertex = entry.getValue();

            System.out.println(key + " => " + thisVertex.toString());

            for(Edge e : thisVertex.getEdges() ){
                System.out.print(e.toString());
            }
            System.out.println();
            System.out.println("All Edges Evaluated");
        }*/
        return false;
    }
}
import java.util.Set;
import java.util.TreeSet;

public class Vertex {

  private String name;
  private TreeSet<Edge> adj;
  public double dest;

  /**
   * Creates a new vertex
   * @param name the name of the vertex
   */
  public Vertex(String name) {
    this.name = name;
    adj = new TreeSet<Edge>();
  }

  public TreeSet<Edge> getEdges() {
      return this.adj;
  }

  /**
   * Returns the set of all edges starting from this vertex.
   * Set shall be ordered with respect to the names of the destination vertices.
   */
  public Set<Edge> allAdjacent() {
      Set<Edge> vertexSet = adj;

      return null;
  }

  public String toString() {

    return name;
  }

  public void addEdge(Edge e) {

      this.adj.add(e);
  }
}

public class Edge implements Comparable<Edge> {

  private Vertex dst;
  private double cost;

  /** Creates a new edge with an associated cost
   * @param dst the destination vertex
   * @param cost the weight of the edge
   */
  public Edge(Vertex dst, double cost) {
    this.dst = dst;
    this.cost = cost;
  }

  public Vertex getDst() {
      return dst;
  }

  @Override
  public int compareTo(Edge o)
  {
      if(o == null)
          return -1;
      if(this == null)
          return -1;
      if( this.dst.toString().compareTo( ((Edge)o).dst.toString() ) == 0 )
          return 0;
      else if ( this.dst.toString().compareTo( ((Edge)o).dst.toString() ) < 0 )
          return 1;
      else 
          return -1;
  }

  public String toString() {
        String theEdgeS = this.dst.toString()+" "+Double.toString(cost);
        return theEdgeS;
      }
}
import java.util.Set;
导入java.util.TreeSet;
公共类顶点{
私有字符串名称;
私有树集;
公共双目标;
/**
*创建一个新顶点
*@param name顶点的名称
*/
公共顶点(字符串名称){
this.name=名称;
adj=新树集();
}
公共树集GetEdge(){
归还这个;
}
/**
*返回从该顶点开始的所有边的集合。
*集合的顺序应与目标顶点的名称有关。
*/
公共集allAdjacent(){
设置顶点集=调整;
返回null;
}
公共字符串toString(){
返回名称;
}
公共无效补遗(边缘e){
本条增补(e);
}
}
公共类边缘实现可比较{
私有顶点dst;
私人双重成本;
/**创建具有关联成本的新边缘
*@param dst目标顶点
*@param消耗了刃的重量
*/
公共边缘(顶点dst,双倍成本){
this.dst=dst;
成本=成本;
}
公共顶点getDst(){
返回dst;
}
@凌驾
公共整数比较(边缘o)
{
如果(o==null)
返回-1;
if(this==null)
返回-1;
if(this.dst.toString().compareTo((Edge)o.dst.toString())==0)
返回0;
else if(this.dst.toString().compare