Results 1 to 6 of 6
- 09-12-2011, 06:05 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 8
- Rep Power
- 0
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; } } } } }
- 09-12-2011, 06:19 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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?
- 09-12-2011, 06:34 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 8
- Rep Power
- 0
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)
- 09-12-2011, 07:07 PM #4
Member
- Join Date
- Sep 2011
- Location
- Athens Greece
- Posts
- 29
- Rep Power
- 0
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!
- 09-12-2011, 07:15 PM #5
Member
- Join Date
- Sep 2011
- Posts
- 8
- Rep Power
- 0
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?
- 09-12-2011, 07:54 PM #6
Member
- Join Date
- Sep 2011
- Location
- Athens Greece
- Posts
- 29
- Rep Power
- 0
Similar Threads
-
Could not find or load main class: c:\java\HelloWorldApp
By Atticus in forum New To JavaReplies: 10Last Post: 02-02-2012, 08:26 PM -
Error: Could not find or load main class HelloWorldApp (HELP)
By couch_mango in forum New To JavaReplies: 29Last Post: 02-02-2012, 08:23 PM -
Failed to load Main-Class manifest attribute from
By karq in forum New To JavaReplies: 5Last Post: 09-16-2011, 07:01 AM -
"Could not find the main class: comparisonDemo.class. Program will exit."
By ziisrick in forum New To JavaReplies: 6Last Post: 05-18-2010, 05:11 PM -
Could not find main class - JDK 1.6
By Syranno in forum New To JavaReplies: 1Last Post: 07-25-2008, 04:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks