• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Weird classpath error + my cool bubblesort algorithm program

 
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I uninstalled jdk1.3 and then rebooted and then reinstalled
jdk1.3 and I still get this classpath error! In the past
an uninstall and reinstall would fix all classpath problems
for me!
Error message is :
Exception in thread "main" java.lang.NoSuchMethodError: main
PS: The whole block of code from here to the end compiles
as one file "BubbleSortArray" and it does compile but does
not run!
http://java.sun.com/j2se/1.3/docs/api/java/lang/NoSuchMethodException.html

Code below:

/**********************************************************
Bubble sort: The bubble sort is very slow but it is the most simple algorithm thus
bubble sort will be the first one we talk about!
If one could only see 2 famous/infamous mountains at the same time, and thus
could compare them , Thus bubble sort can only sort 2 items at a time and swaps
them and then more over one slot and compare again. This is why it is called bubble
sort because the items bubble up and keeps on making passes up the array until
the array is sorted.

*************************************************************/
// BubbleSortArray.java

class BubbleSortArray {
private double[] b; // reference to array
private int numberOfElements; // number of items
public BubbleSortArray( int max) // constructor
{
b= new double[max]; // creating array
numberOfElements = 0; // no items in slots
}
public void insert( double value) // items in slot
{
b[numberOfElements] = value; // insert and increment
numberOfElements++;
}
public void display() // display contents of all slots of array
{
for( int j=0; j<numberOfElements; j++) // this displays all elements<br /> System.out.print(b[j] + " ");<br /> System.out.println(" " );<br /> }<br /> public void BubbleSort()<br /> {<br /> int out, in;<br /> for( out = numberOfElements-1; out>1; out--)
for(in =0; in<out; in++) // outer loop backward<br /> if( b[in] > b[in+1]) // inner loop forward
swap(in, in+1); // swap them
}
protected void swap( int one, int two)
{
double temp = b[one];
b[one] = b[two];
b[two] = temp;
}
}

class BubbleSortExample {
public static void main(String argv[] )
{
int maxSize = 25; // array size : Note always make arrays bigger then you need
BubbleSortArray arr; // reference to array BubbleSortArray
arr = new BubbleSortArray(maxSize); // creates array

/// insert items here

arr.insert( 28250 );// K2 8611 meters
arr.insert( 22835 );// Aconcagua
arr.insert( 16067 );// VINSON MASSIF
arr.insert( 14870 );// MatterHorn
arr.insert( 29028 );//MT.Everest
arr.insert( 9836 );//Dolomites
arr.insert( 28208 );//KANGCHENJUNGA
arr.insert( 17887 );//POPOCATEPETL
arr.insert( 14225 );//longs peak
arr.insert( 5267 );//Katahdin
arr.insert( 20320 ); //Mt. McKinley
arr.display(); // display items
arr.BubbleSort(); // sort them

arr.display(); // and display the sorted array

} // end of the main method/function
} // End of class BubbleSortExample
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Erich,
Your problem is that you are naming the file incorrectly. According to the source code you are giving the file name should be BubbleSortExample. The class BubbleSortArray doesn't have a main method in it. That is what the compiler is trying to tell you! To get it to work correctly:
Save code to file named: BubbleSortExample
Compile code: javac BubbleSortExample.java
Run Code: java BubbleSortExample
Enjoy,
Manfred.
 
erich brant
Ranch Hand
Posts: 246
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am dyslexic, I guess I have to reread my code more!
thanks!
 
It is difficult to free fools from the chains they revere - Voltaire. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic