Results 1 to 1 of 1
Thread: calling a class in another file
- 04-11-2010, 02:59 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
calling a class in another file
i have two different classes in different files and am not able to call the second one from the first..
i get the following error:
cannot find symbol
symbol: class routing
location: class proj.console_io
routing app = new routing ("test.txt");
1st file: (console_io.java)
2nd file: (routing.java)Java Code:package proj; import java.io.*; import java.io.Console; import java.util.*; public class console_io { public static void main(String args[]) throws IOException { Console c = System.console(); String ans="y"; int i=1,j=0,dstn; String w; String num=c.readLine("Number of Vertices::"); j=Integer.parseInt(num); BufferedWriter out=new BufferedWriter(new FileWriter("test.txt")); System.out.println("Enter adjacency matrix::"); while(j>0) { //System.out.println(""); w=c.readLine(); out.write(w); out.newLine(); j--; } out.newLine(); out.close(); dstn=Integer.parseInt(c.readLine("Enter destination vertex::")); } routing app = new routing( "test.txt" ); }
Java Code:package proj; 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 d[] = new int[ graph.length ]; int dC[] = new int[ graph.length ]; int p[] = new int[ graph.length ]; //int vert[]= new int [graph.length]; for( int i = 0; i < graph.length; i++ ){ d[ i ] = 100; dC[ i ] = 100; p[ i ] = -1; } d[ 0 ] = 0; dC[ 0 ] = 0; int i = 0, min = 200, pos = 0; //You can change the min to 1000 to make it the largest number while( i < graph.length ){ //extract minimum for( int j = 0; j < dC.length; j++ ){ if( min > d[ j ] && dC[ j ] != -1 ){ min = d[ j ]; pos = j; } } dC[ pos ] = -1; //relax for( int j = 0; j < graph.length; j++ ){ if( d[ j ] > graph[ pos ][ j ] + d[ pos ] ){ d[ j ] = graph[ pos ][ j ] + d[ pos ]; p[ j ] = pos; // vert[j]=pos; } } i++; min = 200; } for( int j = 0; j < p.length; j++ ){ System.out.print( p[ j ] + " " ); } //for( int j = 0; j < p.length; j++ ){ // System.out.println("Vertice:"+ vert[ j ] + " " ); //} System.out.print( "\n" ); for( int j = 0; j < d.length; j++ ){ System.out.print( d[ j ] + " " ); } System.out.print( "\n" ); } }
Similar Threads
-
Child-Class Calling a Method in a Parent-Class
By Blah_ in forum New To JavaReplies: 5Last Post: 09-29-2009, 02:48 AM -
Calling a class method from another class
By caro in forum New To JavaReplies: 4Last Post: 06-10-2009, 01:12 AM -
problem calling function from class to class
By alin_ms in forum New To JavaReplies: 3Last Post: 12-19-2008, 07:35 PM -
excecuting a jar file by calling a java class
By Lavanya.vitria in forum Advanced JavaReplies: 1Last Post: 12-13-2008, 12:11 PM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks