main运行时报java.lang.NullPointException:
import java.io.*;
import java.util.Vector;
class MGraph
{
private Vector ves;
private int[][] edges;
private int vexnum,arcnum,i,j;
public MGraph(String[] Initves,int[][]Edges,int m,int n) //m,n分别代表顶点数和弧数
{
ves=new Vector <String>(java.util.Arrays.asList(Initves));
for(i=0;i <m;i++)
{ for(j=0;j <m;j++)
edges[i][j]=Edges[i][j];
}
vexnum=m;
arcnum=n;
}
public Vector getVes(){return ves;}
public int getVexnum(){return vexnum;}
public int getArcnum(){return arcnum;}
public int[][] getEdges(){int num[][]=new int[vexnum][vexnum];return num;}
public void setEdges(int[][] Edges)
{for(i=0;i <vexnum;i++)
for(j=0;j <vexnum;j++)
{edges[i][j]=Edges[i][j];}
}
public void setVexnum(int aVexnum)
{vexnum=aVexnum;
}
public void setArcnum(int aArcnum)
{arcnum=aArcnum;
}
}
class Floyd
{ public void folyd(MGraph g)
{ int A[][],path[][];
int i,j,k,n=g.getVexnum();
A=g.getEdges();
path=new int[n][n];
for(i=0;i <n;i++)
for(j=0;j <n;j++)
{
path[i][j]=-1;
}
for(k=0;k <n;k++)
{ for(i=0;i <n;i++)
for(j=0;j <n;j++)
if(A[i][j]>(A[i][k]+A[k][j]))
{A[i][j]=A[i][k]+A[k][j];
path[i][j]=k;
}
}
}
}
class Ppath
{ public void ppath(int path[][],Vector Ves,int i,int j)
{ int k;
k=path[i][j];
if(k==-1)return;
ppath(path,Ves,i,k);
System.out.print(Ves.get(k));
ppath(path,Ves,k,j);
}
}
class Dispath
{ public void dispath(int A[][],int path[][],int n,Vector Ves,Ppath p)
{ int i,j;
for(i=0;i <n;i++)
for(j=0;j <n;j++)
if(A[i][j]==0)
{ if(i!=j)
System.out.print("从"+Ves.get(i)+"到"+Ves.get(j)+"没有符合要求的车次");
}
else
{ System.out.print("从"+Ves.get(i)+"到"+Ves.get(j)+"的路径为:");
System.out.print(Ves.get(i)+",");p.ppath(path,Ves,i,j);System.out.print(Ves.get(j));
}
}
}
class Keyboard
{ static BufferedReader inputStream=new BufferedReader(new InputStreamReader(System.in));
public static int getInteger()
{try{
return(Integer.valueOf(inputStream.readLine().trim()).intValue());
}catch(Exception e)
{
e.printStackTrace();
return 0;
}
}
public static String getString()
{ try{return(inputStream.readLine());
}catch(IOException e){return "0";}
}
}
public class TraffConsults
{ public static void main(String[] args)
{ String[] city={"beijing","tianjin","huhehaote","xuzhou","zhengzhou"};
int[][] route={{0,137,668,0,695},{137,0,0,674,0},{668,0,0,0,0},{0,674,0,0,349},{695,0,0,349,0}};
MGraph g;
g=new MGraph(city,route,5,5);
}
}
------解决方法--------------------------------------------------------
你只是申明了!private int[][] edges;没有new
在[ves=new Vector <String>(java.util.Arrays.asList(Initves)); ]后面new一下
edges = new int[Edges.length][5];
------解决方法--------------------------------------------------------
import java.io.*; import java.util.Vector; class MGraph { private Vector ves; private int[][] edges=null; private int vexnum,arcnum,i,j; public MGraph(String[] Initves,int[][]Edges,int m,int n) //m,n分别代表顶点数和弧数 { ves=new Vector <String>(java.util.Arrays.asList(Initves)); edges = Edges.clone(); //////for(i=0;i <m;i++) { for(j=0;j <m;j++) { System.out.println(edges[i][j]); }}vexnum=m; arcnum=n; } public Vector getVes(){return ves;} public int getVexnum(){return vexnum;} public int getArcnum(){return arcnum;} public int[][] getEdges(){int num[][]=new int[vexnum][vexnum];return num;} public void setEdges(int[][] Edges) {for(i=0;i <vexnum;i++) for(j=0;j <vexnum;j++) {edges[i][j]=Edges[i][j];} } public void setVexnum(int aVexnum) {vexnum=aVexnum; } public void setArcnum(int aArcnum) {arcnum=aArcnum; } }