Results 1 to 13 of 13
  1. #1
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Cannot find symbol method

    Hi everyone. This may be a very simple error to fix but it is not too obvious to me at the moment and no matter how much research I do I can't seem to understand this concept. I was given the Java code for a project and I am supposed to build unit tests to test the performance of seven sorting algorithms and I am getting the following error in my Lab1Test file...cannot find symbol: method sorta(int[]) location: class Lab1Test. Thanks in advance for your help :)

    Lab1.java

    Java Code:
    package funcollege.comp10062.perflib;
    
    import java.text.DecimalFormat;
    import java.util.Arrays;
    import java.util.Random;
    
    public class Lab1 {
     
      private static int[] buildrandomarray(int size, int studentId) {
    
        Random r = new Random(studentId); 
        int array[] = new int[size];
    
        for (int i = 0; i < array.length; i++) {
          array[i] = r.nextInt();
        }
        return array;
      }
      
      public static void main(String[] args) {
        
        final int studentId = 299135;
        int size;
        long start, t;
    
        int array[] = buildrandomarray(10, studentId);
    
        Sort.sorta(array); 
    
        
    for (size=10; size<=1000000; size=size*10)
        {
        int n = size;
        array = buildrandomarray(n,studentId);
        start = System.nanoTime();
        array = buildrandomarray(n, studentId);
        Sort.sorta(array);
        t = (System.nanoTime() - start) / 1000;
        System.out.printf("Sort A took %d us to sort %d elements\n", t, n);
        }
    }
    }
    Lab1Test.java

    Java Code:
    package funcollege.comp10062.perflib;
    
    import org.junit.After;
    import org.junit.AfterClass;
    import org.junit.Before;
    import org.junit.BeforeClass;
    import org.junit.Test;
    import static org.junit.Assert.*;
    
    
    public class Lab1Test {
        
        public Lab1Test() {
        }
        
        @BeforeClass
        public static void setUpClass() {
        }
        
        @AfterClass
        public static void tearDownClass() {
        }
        
        @Before
        public void setUp() {
        }
        
        @After
        public void tearDown() {
        }
        // TODO add test methods here.
        // The methods must be annotated with annotation @Test. For example:
        //
        // @Test
        // public void hello() {}
        
        @Test
    
    public void test_SortA(){
    	int  testdata [] = {5,7,4,1,2,10,3,6,8,9};
    	int expectResult[] = {1,2,3,4,5,6,7,8,9,10};
    	int result = Lab1Test.[B]sorta[/B](testdata);
    	assertEquals(expectResult,result);
    }
    }
    Sort.java

    XML Code:
    package funcollege.comp10062.perflib;
    
    public class Sort {
    
        public Sort() {
            
        }
    
        public static void sorta(int[] array) {
            
        }
    
        public static void sorte(int[] array) {
           
        }
    
        public static void sortc(int[] array) {
            
        }
    
        private static void x1(int[] data, int first, int n) {
            
        }
    
        private static void x2(int[] data, int first, int n1, int n2) {
            
        }
    
        public static void sortd(int[] a) {
            
        }
    
        public static void sortb(int[] a) {
            
        }
    
        public static void sortf(int[] a) {
            
        }
    
        private static void iS(int[] a, int start, int increment) {
            
        }
    
        public static void sortg(int[] a) {
           
        }
    }

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,358
    Rep Power
    6

    Default Re: Cannot find symbol method

    What's strange about that? Lab1Test does not have a sorta() method. The Sort class does.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,029
    Rep Power
    6

    Default Re: Cannot find symbol method

    You are trying to access sorta as a static method of Lab1Test. But it is not in that class. It is in the Sort class.

    Regards,
    Jim
    Last edited by jim829; 04-10-2014 at 06:05 PM. Reason: Slow draw McGraw strikes again
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,358
    Rep Power
    6

    Default Re: Cannot find symbol method

    Sorry, I'm going to switch off my spam mode and actually do some work.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: Cannot find symbol method

    Quote Originally Posted by gimbal2 View Post
    What's strange about that? Lab1Test does not have a sorta() method. The Sort class does.
    I think that part is obvious to anyone but what method do I apply instead? Or should I create a sort method in the Lab1Test class?

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,029
    Rep Power
    6

    Default Re: Cannot find symbol method

    Well, it didn't seem to be obvious to you. Whether you should put the method in Lab1Test or call it from Sort is dependent upon the design and requirements of your assignment. That is something we (or at least I) cannot answer.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: Cannot find symbol method

    With all due respect I think you just jumped to conclusions about what my problem really was and maybe I could have been more specific. But I understand.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,029
    Rep Power
    6

    Default Re: Cannot find symbol method

    Nope! Didn't jump to conclusions.

    I am getting the following error in my Lab1Test file...cannot find symbol: method sorta(int[]) location: class Lab1Test.
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: Cannot find symbol method

    Quote Originally Posted by jim829 View Post
    Nope! Didn't jump to conclusions.



    Regards,
    Jim
    Well kind of. I mean I showed the error displayed by NetBeans but then you assumed I didn't know that the sort method existed somewhere in the project. But you know what that's fine, I'm not here to argue.

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,778
    Blog Entries
    7
    Rep Power
    21

    Default Re: Cannot find symbol method

    Quote Originally Posted by gusten View Post
    Well kind of. I mean I showed the error displayed by NetBeans but then you assumed I didn't know that the sort method existed somewhere in the project. But you know what that's fine, I'm not here to argue.
    Yes you are ...

    kind regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    gusten is offline Member
    Join Date
    Jul 2013
    Posts
    19
    Rep Power
    0

    Default Re: Cannot find symbol method

    Quote Originally Posted by JosAH View Post
    Yes you are ...

    kind regards,

    Jos ;-)
    No you are

  12. #12
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,778
    Blog Entries
    7
    Rep Power
    21

    Default Re: Cannot find symbol method

    Quote Originally Posted by gusten View Post
    No you are
    Oh dear; salvation is on its way: De Morgan's laws - Wikipedia, the free encyclopedia

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,358
    Rep Power
    6

    Default Re: Cannot find symbol method

    What goes through the mind of a person who asks for help and then rejects ANY form of it?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Help With cannot find symbol method Error
    By decon101 in forum New To Java
    Replies: 3
    Last Post: 05-09-2012, 10:04 PM
  2. cannot find symbol: method Scanner(java.io.InputStream)
    By shandog1079 in forum New To Java
    Replies: 2
    Last Post: 03-25-2011, 05:47 AM
  3. Replies: 2
    Last Post: 03-08-2011, 04:08 PM
  4. HELP! can't find symbol-method
    By Jack9333 in forum New To Java
    Replies: 2
    Last Post: 03-04-2011, 02:48 AM
  5. cannot find symbol - method iterator()
    By D.Calladine in forum New To Java
    Replies: 1
    Last Post: 11-30-2010, 01:13 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
  •