help needed 3 errors

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2006
Posts: 9
Reputation: fastmike is an unknown quantity at this point 
Solved Threads: 0
fastmike fastmike is offline Offline
Newbie Poster

help needed 3 errors

 
0
  #1
Oct 22nd, 2006
hi. well can anyone please tell me y am i getting this error and how can i get rid of it..

  1. import java.io.RandomAccessFile;
  2. import java.io.IOException;
  3. import java.util.StringTokenizer;
  4. import java.util.NoSuchElementException;
  5. public class routing{
  6. public static void main( String args[] ){
  7. routing app = new routing( args[ 0 ] );
  8. }
  9. public routing( String inFile ){
  10. try{
  11. RandomAccessFile file = new RandomAccessFile( inFile, "rw" );
  12. String tmp = file.readLine(); int i = 0;
  13. while( tmp != null ){ tmp = file.readLine(); i++; }
  14. file.seek( 0 ); tmp = file.readLine();
  15. int graph[][]; graph = new int[ i ][ i ]; i = 0;
  16. while( tmp != null ){
  17. StringTokenizer sT = new StringTokenizer( tmp, " " ); int j = 0;
  18. while( sT.hasMoreTokens() ){ graph[ i ][ j++ ] = Integer.parseInt( sT.nextToken() ); }
  19. i++; tmp = file.readLine();
  20. }
  21. file.close();
  22. dijkstra( graph );
  23. }
  24. catch( IOException io ){ System.err.println( io.toString() ); System.exit( 1 ); }
  25. catch( RuntimeException re ){ System.err.println( re.toString() ); System.exit( 1 ); }
  26. }
  27. public void dijkstra( int graph[][] ){
  28. int nVertc = graph.length; //total number of vertices
  29. int numMarked = 0; //number of marked vertices
  30. int[] marked = new int [nVertc]; //List of marked vertices
  31. int[] min_weight = new int [nVertc]; //List of min-weights
  32. for(int count = 0; count < nVertc; count++) { //Initialize min-weights to weights of lines from vertex 0
  33. min_weight[count] = graph[0][count];
  34. }
  35. while(numMarked < nVertc) { //Process until no vertex is left unmarked
  36. int vertex = minVertex(nVertc, marked, numMarked, min_weight); //Choose an unmarked vertex with smallest calculated min_weight
  37. // and then mark it
  38. marked[numMarked] = vertex;
  39. numMarked++;
  40. for (int count = 1; count < nVertc; count++) { //If it lessens the weight of the min-path from 0 to any unmarked
  41. // vertices, record this new weight.
  42. if(!elementOf(marked, numMarked, count))
  43. if(min_weight[count] > min_weight [vertex] + graph[vertex][count] || min_weight[count] == -1)
  44. if(min_weight[vertex] > 0 && graph [vertex][count] > 0)
  45. min_weight[count] = min_weight [vertex] + graph[vertex][count];
  46. System.out.println("The cheapest cost is:" +graph);
  47. }
  48. }
  49. return min_weight;
  50. }
  51. private static int minVertex(int nVertc, int [] marked, int numMarked, int[] graph) {
  52. int minIndex = -1; //Index of minimum vertex
  53. int minValue = -1; //Weight of minimum vertex
  54. for(int vertex = 0; vertex < nVertc; vertex++) {
  55. if(!elementOf(marked, numMarked, vertex)) {
  56. if((graph[vertex] >= 0 && graph[vertex] < minValue) || minValue==-1) {
  57. minIndex=vertex;
  58. minValue=graph[vertex];
  59. }
  60. }
  61. }
  62. }
  63. }

these are the errors i am getting..

  1. symbol : method elementOf (int[],int,int)
  2. location: class routing
  3. if(!elementOf(marked, numMarked, count))
  4. ^
  5. routing.java:54: cannot return a value from method whose result type is void
  6. return min_weight;
  7. ^
  8. routing.java:60: cannot resolve symbol
  9. symbol : method elementOf (int[],int,int)
  10. location: class routing
  11. if(!elementOf(marked, numMarked, vertex)) {
  12. ^
  13. 3 errors

Thanks alot for listening and reading
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 229
Reputation: DavidRyan is an unknown quantity at this point 
Solved Threads: 11
DavidRyan's Avatar
DavidRyan DavidRyan is offline Offline
Posting Whiz in Training

Re: help needed 3 errors

 
0
  #2
Oct 22nd, 2006
This error:
  1. routing.java:54: cannot return a value from method whose result type is void
  2.  
  3. return min_weight;
Is because your method:
  1. public void dijkstra( int graph[][] ){
is declared as void, and therefore cannot return a value (min_weight is an int[]). Either change the method's return type from void to int[], which will allow your method to return the value, or remove the return "min_weight;" line. I suspect you would want to change the method's return type.

As for the other errors, they are because the compiler can't find the elementOf method. I've not had much luck finding it either, and it isn't in Java.io.RandomAccessFile or Java.io.StringTokeniser. Could you tell us where you expect it to be?
Please anyone, correct me if I am wrong. It is the best way for me to learn.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC