Results 1 to 2 of 2
- 07-12-2010, 09:37 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 1
- Rep Power
- 0
Java.lang.ArrayIndexOutOfBoundsException
Hi,
I am somewhat of a semi-intermediate Java programmer. I am having problems with an Array Index Out of Bounds Exception=0 at genGraph2.main(genGraph2.java:312) and I don't really see what the problem is. I've looked and looked for possible errors. I am trying to use a file and read multiple lines in order to compare a source node and multiple destination nodes in order to determine if edges exist. This code is somewhat outdated but I am implementing changes in it. I am using NetBeans but I am running it in the command prompt. In the command prompt I am receiving the following errors:
Here is the code with the line areas highlighted.Java Code:java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0 at java util.Vector.get(Unknown Source) at genGraph.checkconnected(genGraph.java: 515) at genGraph.main(genGraph.java:381)
Java Code:class genGraph2 { static TreeMap[] nodePositions; static int numNodes = -1; static double maxTransRange = 250; static double distThreshold = -1; static Random randN = new Random(System.currentTimeMillis()*10); static double samplingFreq = 0.25; static double simTime = -1; public static void main(String[] args) { try { [COLOR="Red"](line 312)FileInputStream fis = new FileInputStream(args[0]);[/COLOR] simTime = Double.parseDouble(args[1]); //distThreshold = Double.parseDouble(args[2]); ObjectInputStream ois = new ObjectInputStream(fis); nodePositions = (TreeMap[]) ois.readObject(); numNodes = nodePositions.length; ois.close(); fis.close(); Vector sdPairs = new Vector(); FileReader fr = new FileReader("singleSD.txt"); BufferedReader br = new BufferedReader(fr); String line = null; while ( (line = br.readLine() )!= null) { StringTokenizer stk = new StringTokenizer(line); int source = Integer.parseInt(stk.nextToken()); int dest = Integer.parseInt(stk.nextToken()); sdPairs.add(source+" "+dest); } if(!pathExists){ topology topo = new topology(); topo.construct(currentTime); [COLOR="Red"](line 381) if (!checkConnected(topo.getNodeList(), topo.getAdjList())){[/COLOR] System.out.println(" "); System.out.println(" the topology is not connected at time: "+currentTime); System.out.println("Avg Lifetime:" + (totalLifetime/lifetimeCounter)); continue timeLoop; } static boolean checkConnected(Vector nodeList, TreeMap adjList) { int rootID = (int) (Math.floor(randN.nextDouble()*nodeList.size())); Vector nodesExplored = new Vector(); Vector nodesFIFOQueue = new Vector(); nodesExplored.add(new Integer(rootID)); nodesFIFOQueue.add(new Integer(rootID)); while (nodesFIFOQueue.size() > 0) { int firstNodeID = ( (Integer) nodesFIFOQueue.get(0)).intValue(); [COLOR="red"](line 515) Node firstNode = (Node) nodeList.get(firstNodeID);[/COLOR] Vector neighbList = (Vector) adjList.get(new Integer(firstNodeID)); for (int neighbIndex = 0; neighbIndex < neighbList.size(); neighbIndex++) { int neighbID = ( (Integer) neighbList.get(neighbIndex)).intValue(); if (!nodesExplored.contains(new Integer(neighbID))) { nodesExplored.add(new Integer(neighbID)); nodesFIFOQueue.add(new Integer(neighbID)); } } nodesFIFOQueue.remove(0); } if (nodesExplored.size() < nodeList.size()) return false; // underlying network not connected else return true; // underlying network connected }
I could really use some advice thank you in advance.Last edited by Fubarable; 07-12-2010 at 10:27 PM. Reason: Moderator edit: code tags added
- 07-12-2010, 10:11 PM #2
Similar Threads
-
java.lang.ArrayIndexOutOfBoundsException: 6
By pyat77 in forum Java AppletsReplies: 6Last Post: 03-06-2010, 01:12 PM -
java.lang.ArrayIndexOutOfBoundsException
By niteshwar.bhardwaj in forum Java 2DReplies: 0Last Post: 02-13-2009, 07:29 AM -
java.lang.ArrayIndexOutOfBoundsException
By mensa in forum Java 2DReplies: 7Last Post: 05-05-2008, 09:09 AM -
java.lang.ArrayIndexOutOfBoundsException
By riccian in forum New To JavaReplies: 0Last Post: 03-18-2008, 09:38 AM -
java.lang.ArrayIndexOutOfBoundsException
By mew in forum New To JavaReplies: 2Last Post: 12-02-2007, 09:40 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks