Results 1 to 6 of 6
  1. #1
    blaqkout is offline Member
    Join Date
    Sep 2011
    Posts
    8
    Rep Power
    0

    Default Could not find or load main class BubbleSort.class

    I'm getting Could not find or load main class BubbleSort.class when I try to run java BubbleSort file1.txt

    any help would be appreciated.

    thanks!

    Java Code:
    import java.io.*;
    
    public class BubbleSort{
    	public static void main(String[] args) throws IOException{
    		
    		int i, count = 0;
    		int[] array = new int[100000];
    		File f = new File(args[0]);
    		FileReader in = new FileReader(f);
    		BufferedReader buf = new BufferedReader(in);
    		
    		String s = buf.readLine();
    		
    		while (s!=null){
    			array[count] = Integer.parseInt(s);
    			s = buf.readLine();
    		}
    		
    		buf.close();
    		
    		
    		System.out.println("Values Before the sort:\n");
    		for(i = 0; i < array.length; i++)
    			System.out.print( array[i]+"  ");
    		System.out.println();
    		bubble_srt(array, array.length);
    		System.out.print("Values after the sort:\n");
    		for(i = 0; i <array.length; i++)
    			System.out.print(array[i]+"  ");
    		System.out.println();
    		System.out.println("PAUSE");
    	}
    
    	public static void bubble_srt( int a[], int n ){
    		int i, j,t=0;
    		for(i = 0; i < n; i++){
    			for(j = 1; j < (n-i); j++){
    				if(a[j-1] > a[j]){
    					t = a[j-1];
    					a[j-1]=a[j];
    					a[j]=t;
    				}
    			}
    		}
    	}
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Could not find or load main class BubbleSort.class

    How are you running it?
    What (full) command are you using?
    Where are you running it from?
    Where is the BubbleSort class file located?

    Have you compiled BubbleSort.java?

  3. #3
    blaqkout is offline Member
    Join Date
    Sep 2011
    Posts
    8
    Rep Power
    0

    Default Re: Could not find or load main class BubbleSort.class

    I'm running it from the command line;

    java BubbleSort smallArray.txt

    C:\Users\%username%\workspace\BubbleSort\bin\


    I'm using eclipse Indigo to create it. When I run the code in eclipse I get the error even after I config the run to let me choose a file.

    Exception in thread "main" java.io.FileNotFoundException: C:\Users\%username% (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileReader.<init>(Unknown Source)
    at BubbleSort.main(BubbleSort.java:16)

  4. #4
    DeNiS_M is offline Member
    Join Date
    Sep 2011
    Location
    Athens Greece
    Posts
    29
    Rep Power
    0

    Default Re: Could not find or load main class BubbleSort.class

    Maybe you should enter the full path to the smallArray.txt, because the way you run it the interpreter is trying to locate the file in the running directory!

  5. #5
    blaqkout is offline Member
    Join Date
    Sep 2011
    Posts
    8
    Rep Power
    0

    Default Re: Could not find or load main class BubbleSort.class

    I just tried it with java BubbleSort "C:\Temp\smallArray.txt" and it at least executed. How can I fix the code to make it so I don't have to have explicit paths to the file?

  6. #6
    DeNiS_M is offline Member
    Join Date
    Sep 2011
    Location
    Athens Greece
    Posts
    29
    Rep Power
    0

    Post Re: Could not find or load main class BubbleSort.class

    In Eclipse go Run -> Run Configuration.In the Java Application right click New... and in the arguments tab write the path to the file.

Similar Threads

  1. Replies: 10
    Last Post: 02-02-2012, 09:26 PM
  2. Replies: 29
    Last Post: 02-02-2012, 09:23 PM
  3. Replies: 5
    Last Post: 09-16-2011, 08:01 AM
  4. Replies: 6
    Last Post: 05-18-2010, 06:11 PM
  5. Could not find main class - JDK 1.6
    By Syranno in forum New To Java
    Replies: 1
    Last Post: 07-25-2008, 05:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •