hi. well can anyone please tell me y am i getting this error and how can i get rid of it..

import java.io.RandomAccessFile;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.NoSuchElementException;
public class routing{
        public static void main( String args[] ){
                routing app = new routing( args[ 0 ] );
        }
        public routing( String inFile ){
                try{
                        RandomAccessFile file = new RandomAccessFile( inFile, "rw" );
                        String tmp = file.readLine(); int i = 0;
                        while( tmp != null ){ tmp = file.readLine(); i++; }
                        file.seek( 0 ); tmp = file.readLine();
                        int graph[][]; graph = new int[ i ][ i ]; i = 0;
                        while( tmp != null ){
                                StringTokenizer sT = new StringTokenizer( tmp, " " ); int j = 0;
                                while( sT.hasMoreTokens() ){ graph[ i ][ j++ ] = Integer.parseInt( sT.nextToken() ); }
                                i++; tmp = file.readLine();
                        }
                        file.close();
                        dijkstra( graph );
                }
                catch( IOException io ){ System.err.println( io.toString() ); System.exit( 1 ); }
                catch( RuntimeException re ){ System.err.println( re.toString() ); System.exit( 1 ); }
        }
        public void dijkstra( int graph[][] ){
          int nVertc = graph.length;   //total number of vertices
          int numMarked = 0;    //number of marked vertices
          int[] marked = new int [nVertc];    //List of marked vertices
          int[] min_weight = new int [nVertc];  //List of min-weights
            for(int count = 0; count < nVertc; count++) {    //Initialize min-weights to weights of lines from vertex 0
                min_weight[count] = graph[0][count];
    }
     while(numMarked < nVertc) {      //Process until no vertex is left unmarked
        int vertex = minVertex(nVertc, marked, numMarked, min_weight); //Choose an unmarked vertex with smallest calculated min_weight
                                                                            // and then mark it
                marked[numMarked] = vertex;
                 numMarked++;
       for (int count = 1; count < nVertc; count++) {  //If it lessens the weight of the min-path from 0 to any unmarked
                                                            // vertices, record this new weight.
        if(!elementOf(marked, numMarked, count))
        if(min_weight[count] > min_weight [vertex] +  graph[vertex][count] || min_weight[count] == -1)
         if(min_weight[vertex] > 0 && graph [vertex][count] > 0)
        min_weight[count] = min_weight [vertex] + graph[vertex][count];
        System.out.println("The cheapest cost is:" +graph);
       }
    }
          return min_weight;
         }
        private static int minVertex(int nVertc, int [] marked, int numMarked, int[] graph) {
        int minIndex = -1; //Index of minimum vertex
        int minValue = -1; //Weight of minimum vertex
        for(int vertex = 0; vertex < nVertc; vertex++) {
        if(!elementOf(marked, numMarked, vertex)) {
        if((graph[vertex] >= 0 && graph[vertex] < minValue) || minValue==-1) {
        minIndex=vertex;
        minValue=graph[vertex];
        }
     }
  }
 }
 }

these are the errors i am getting..

symbol  : method elementOf (int[],int,int)
location: class routing
        if(!elementOf(marked, numMarked, count))
            ^
routing.java:54: cannot return a value from method whose result type is void
          return min_weight;
                 ^
routing.java:60: cannot resolve symbol
symbol  : method elementOf (int[],int,int)
location: class routing
        if(!elementOf(marked, numMarked, vertex)) {
            ^
3 errors

Thanks alot for listening and reading

This error:

routing.java:54: cannot return a value from method whose result type is void

          return min_weight;

Is because your method:

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.