1-Error: Could not find or load main class BasicSorting_1 2-Caused by: java.lang.NoClassDefFoundError: 3- Sorting/BasicSorting_1 (wrong name: BasicSorting_1)// enter image description here
package Sorting;
import java.util.*;
public class BasicSorting_1 {
public static void bubbleSort(int num[]) {
int n = num.length;
for (int turn = 0; turn < n - 1; turn ) {
for (int j = 0; j < n - 1; j ) {
if (num[j] > num[j 1]) {
// swap
int temp = num[j];
num[j] = num[j 1];
num[j 1] = temp;
}
}
}
}
public static void display(int num[]) {
int n = num.length;
for (int i = 0; i < n; i ) {
System.out.print(num[i] " ");
}
System.out.println();
}
public static void main(String[] args) {
int num[] = { 2, 3, 1, 7, 5 };
bubbleSort(num);
display(num);
}
}
CodePudding user response:
It is easy. Look at the error when calling the java.uti
library. I suspect it's due to the ide
you're using. Try another ide
, such as Eclipse, NetBeans, etc
. or check the library is it there?!
CodePudding user response:
Maybe, you are running the 'project' instead of just the class BasicSorting_1. Then this error may apear because you have the "main method" in both classes (BasicSorting and BasicSorting_1), then Java can't determine wich class he will use as 'main'.
Try running just the single java file;
If that's not working, try checking out the package(if you really have it):
package Sorting;