Results 1 to 4 of 4
  1. #1
    Lorelai is offline Member
    Join Date
    Oct 2011
    Posts
    8
    Rep Power
    0

    Default Array cannot be resolved

    I have been trying to find why I am getting this error and cannot seem to get on the right path. I am writing code to take in user inputed test scores through a JOptionPane and store the inputs into two arrays: one for test scores and one for student names. I then need to sort through the arrays to arrange them in order. I have created my arrays, as well as the method to sort the array, but am experiencing a "[array name] cannot be resolved" error. Can someone help me get on the right page? Why is this error occurring? What can I do to fix it?

    Thank you for your help!!

    Lorelai

    Java Code:
    import javax.swing.JOptionPane;
    
    
    
    public class P9 {
    	public static void main(String[] args) {
    	
    		     	    	 
    			int negativeScore = 1;
    			
    			while (negativeScore > 0) {
    			int i = 0;
    			int [] testScoreArray= new int[50];
    			String [] studentNameArray = new String [50];
    			String testScoreInputString = JOptionPane.showInputDialog(null, "What was the test score? Enter a negative (-) to end the program. ");
    			int testScoreInt = Integer.parseInt(testScoreInputString);
    			
    			if (testScoreInt <0) {
    				negativeScore = 0;
    				break;
    			}
    			
    			testScoreArray[i] = testScoreInt;
    
    			
    			studentNameArray[i] = JOptionPane.showInputDialog(null, "What is the name of the student?");
    			
    			i++;
    			}
    			// Sort the list
    		    selectionSort(testScoreArray]);
    	} //end main method
    
    		  /*method for printing numbers
    		  static void printList(int[] list) {
    		    for (int i = 0; i < list.length; i++)
    		      System.out.print(list[i] + "  ");
    		    System.out.println();
    		  }  end printList method*/
    
    		  //method for sorting the numbers
    		  static void selectionSort(int[] list) {
    		    for (int i = list.length - 1; i >= 1; i--) {
    		      // Find the maximum in the list[0..i]
    		      int currentMax = list[0];
    		      int currentMaxIndex = 0;
    
    		      for (int j = 1; j <= i; j++) {
    		        if (currentMax < list[j]) {
    		          currentMax = list[j];
    		          currentMaxIndex = j;
    		        } //end if
    		      }// end for with j as index
    
    		      // Swap list[i] with list[currentMaxIndex] if necessary;
    		      if (currentMaxIndex != i) {
    		        list[currentMaxIndex] = list[i];
    		        list[i] = currentMax;
    		      }// end if
    		    }// end for with i as index
    		  } //end selectionSort method
    		} //end SelectionSort class

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Array cannot be resolved

    What is the exact error message you receive?

  3. #3
    Lorelai is offline Member
    Join Date
    Oct 2011
    Posts
    8
    Rep Power
    0

    Default Re: Array cannot be resolved

    I am using eclipse; it won't let me even run the code, the only error I can see is the "testScoreArray cannot be resolved"

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,247
    Rep Power
    19

    Default Re: Array cannot be resolved

    On which line? And fix your indents/outdents, they're all over the place.

    db

    edit Check your syntax. You have a ] that doesn't belong.
    Last edited by DarrylBurke; 04-06-2012 at 06:56 AM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Cannot be resolved to a type
    By Naxix in forum AWT / Swing
    Replies: 1
    Last Post: 03-18-2012, 12:16 PM
  2. bundles not resolved
    By FakeRabbit in forum Eclipse
    Replies: 2
    Last Post: 03-13-2012, 10:13 AM
  3. canvasObject cannot be resolved.
    By falconfetus8 in forum New To Java
    Replies: 10
    Last Post: 12-30-2011, 11:42 PM
  4. Array cannot be resolved
    By aqeel2010 in forum New To Java
    Replies: 4
    Last Post: 10-07-2011, 06:38 PM
  5. HttpServletRequest cannot be resolved-- Help me
    By hphuoc in forum Java Servlet
    Replies: 1
    Last Post: 04-26-2011, 09:23 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
  •