Results 1 to 6 of 6
  1. #1
    theefancyone is offline Member
    Join Date
    Feb 2015
    Posts
    4
    Rep Power
    0

    Default "No main methods, applets. or MIDIlets found in file" in these codes. Please help?

    Hello!

    I've compiled all three programs without any problem. However if I test it, that message will show up. I'm using jGrasp as the program. Is there something that I am missing?

    Code 1 (Selection sort):

    public class SelectionSort{
    /** The method for sorting the numbers */
    public static void selectionSort(double[] list){
    for (int i=0; i<list.length - 1; i++){
    //Find the minimum in the list[i..list.length-1]
    double currentMin = list[i];
    int currentMinIndex=i;

    for (int j=i+1; j>list.length; j++){
    if (currentMin > list[j]){
    currentMin = list[j];
    currentMinIndex = j;
    }
    }

    //Swap list[i] with list[currentMinIndex] if necessary;
    if (currentMinIndex !=i){
    list[currentMinIndex] = list[i];
    list[i] = currentMin;
    }
    }
    }
    }

    Code 2 (Linear search):

    public class LinearSearch{
    /** The method for finding a key in the list */
    public static int linearSearch(int[] list, int key){
    for (int i=0; i<list.length; i++){
    if (key == list[i])
    return i;
    }

    return -1;
    }
    }

    Code 3 (Binary search):

    public class BinarySearch{
    /** Use binary search to find the key in the list */
    public static int binarySearch(int[] list, int key){
    int low=0;
    int high=list.length-1;

    while (high >= low){
    int mid=(low + high)/2;
    if (key < list[mid])
    high=mid -1;
    else if (key == list[mid])
    return mid;
    else
    low = mid + 1;
    }

    return - low - 1; // Now high < low, key not found
    }
    }

    I've been trying to figure this out for the past week. Thank you. :)
    Last edited by theefancyone; 02-26-2015 at 08:03 PM.

  2. #2
    Psychrom is offline Member
    Join Date
    Feb 2015
    Posts
    4
    Rep Power
    0

    Default Re: "No main methods, applets. or MIDIlets found in file" in these codes. Please help

    You're missing a main method: you need a main method, applet, or MIDIlet.
    Here is a simple example.

    public static void main(String[] args) {
    //code here is run when the program starts up.
    }

    The main method is called whenever a java program is started. The only exception is in applets, where they're not calling "main" but "init".
    Consider combining those classes together into a single class, and having those search/sort methods all contained in one single file, possibly named "DataOperations" or something.
    I find it easier to work with one file containing a single class with multiple methods than multiple classes in multiple files for a single method.

  3. #3
    theefancyone is offline Member
    Join Date
    Feb 2015
    Posts
    4
    Rep Power
    0

    Default Re: "No main methods, applets. or MIDIlets found in file" in these codes. Please help

    Quote Originally Posted by Psychrom View Post
    You're missing a main method: you need a main method, applet, or MIDIlet.
    Here is a simple example.

    public static void main(String[] args) {
    //code here is run when the program starts up.
    }

    The main method is called whenever a java program is started. The only exception is in applets, where they're not calling "main" but "init".
    Consider combining those classes together into a single class, and having those search/sort methods all contained in one single file, possibly named "DataOperations" or something.
    I find it easier to work with one file containing a single class with multiple methods than multiple classes in multiple files for a single method.
    Alright, so far I was able to compile and test both Linear and Binary searches with no problem, using your method of public static void main(String[] args);

    Right now I am doing the same with Selection Sort (1st code posted on my question) and it's not working as such. I compile it and it gives me errors different from the message posted. Thank you.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: "No main methods, applets. or MIDIlets found in file" in these codes. Please help

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: "No main methods, applets. or MIDIlets found in file" in these codes. Please help

    Quote Originally Posted by theefancyone View Post
    Right now I am doing the same with Selection Sort (1st code posted on my question) and it's not working as such. I compile it and it gives me errors different from the message posted. Thank you.
    And you don't think actually posting the errors might help us?

    Also, take Darryl's hint and please use code tags when posting code.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Psychrom is offline Member
    Join Date
    Feb 2015
    Posts
    4
    Rep Power
    0

    Default Re: "No main methods, applets. or MIDIlets found in file" in these codes. Please help

    I found some things you might want to take a look at. With no errors given, this is all that I can see that is wrong with your code. There may be more.
    Provide your errors, or I will be unable to help any further.

    Java Code:
    public class SelectionSort{
    /* The method for sorting the numbers */
                                                              
    public static void selectionSort(double[] list){                                
    double currentMin = 0;                                                               // Initialize variables outside of loops
    int currentMinIndex = 0;                             
    for (int i=0; i<list.length - 1; i++){                                             //Suggest using enhanced loop, if possible:   for(double i : list) 
    //Find the minimum in the list[i.list.length-1]
    currentMin = list[i];                                                                  //Initialize variables outside of loops. see above for correct placement. 
    currentMinIndex=i;
    
    for (int j=i+1; j>list.length; j++){
    if (currentMin > list[j]){
    currentMin = list[j];
    currentMinIndex = j;
    }
    }
    
    //Swap list[i] with list[currentMinIndex] if necessary                       // You dont need ; for comments
    if (currentMinIndex !=i){                                                            
    list[currentMinIndex] = list[i];
    list[i] = currentMin;
    }
    }
    }
    }
    Last edited by Psychrom; 02-27-2015 at 04:59 PM.

Similar Threads

  1. Replies: 3
    Last Post: 05-22-2013, 06:49 AM
  2. Replies: 1
    Last Post: 10-23-2012, 03:47 PM
  3. Replies: 2
    Last Post: 06-20-2012, 12:18 AM
  4. Replies: 0
    Last Post: 04-01-2012, 06:16 AM
  5. Replies: 12
    Last Post: 12-05-2008, 05:37 AM

Posting Permissions

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