| | |
help needed 3 errors
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2006
Posts: 9
Reputation:
Solved Threads: 0
hi. well can anyone please tell me y am i getting this error and how can i get rid of it..
these are the errors i am getting..
Thanks alot for listening and reading
Java Syntax (Toggle Plain Text)
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..
Java Syntax (Toggle Plain Text)
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: Is because your method: 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?
Java Syntax (Toggle Plain Text)
routing.java:54: cannot return a value from method whose result type is void return min_weight;
Java Syntax (Toggle Plain Text)
public void dijkstra( int graph[][] ){
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.
![]() |
Similar Threads
- help needed with errors (C++)
- IP Banned in Windows 98 (Non-network) (Windows 95 / 98 / Me)
Other Threads in the Java Forum
- Previous Thread: Arrays(Binay Search)
- Next Thread: If
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database defaultmethod development dice dragging ebook eclipse error event exception formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide image infinite input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows





