s d
s d

Reputation: 311

import java.util.arrays is not resolved

I'm a new student in computer science learning Java and using Eclipse and we are now working on arrays but when I tried to practice arrays on my own time did I discover that something was wrong when I imported the Arrays class.

Eclipse said The import java.util.Arrays; cannot be resolved.

I've checked the solutions provided already and it did not help. I have configured a new build path (JRE System Library JRE 1.8.0-60) and have set it to both Alternate JRE and Workspace Default and have even downloaded the newest Java Runtime Environment as well a fresh download of Eclipse but nothing is working.

Is there something I am missing?

EDIT 1: Yes I have used Project>Clean, it didn't work.

EDIT 2: I am using Eclipse Helios and I've run it in a online IDE and it works fine. But NOT in Eclipse for some reason.

Code (note: I worked on this at school and it was fine. On my own computer is where the problem came up):

import java.util.Arrays;



public class Chap7Practice {


public static void main(String[] args) {

    String [] deck = new String[52];

    final String [] Suits = {"Spades",  "Diamonds", "Clubs", "Hearts" };
    final String [] Ranks = { "Ace","two", "three", "four", "five","six", "seven", 
            "eight", "nine","ten", "Jack", "Queen", "King"};


    int counter = 0;
    for(int s= 0; s<Suits.length; s++){
        for(int r = 0; r<Ranks.length; r++){
            String card = Ranks[r] + " of " + Suits[s];
            deck[counter] = card;
            ++counter;
        }
    }

    String [] deck2; //not a good way to copy =deck;
    deck2 = new String[52];
    for(int i = 0; i<deck.length; i++){
        deck2[i] = deck[i];
    }

    System.out.println(Arrays.toString(deck));

}



}

Upvotes: 1

Views: 15156

Answers (2)

s d
s d

Reputation: 311

I looked at the Eclipse version I had and somehow I had downloaded the wrong one. I did a fresh install which was exactly the same but it works now. I am not exactly sure what happened because I go through the same installer that is on the Eclipse website so what down the line caused the problem is still a mystery to me.

Upvotes: 0

RockAndRoll
RockAndRoll

Reputation: 2287

Try this

  • Right click on project
  • Select BuildPath
  • Select Configure BuildPath
  • Select Libraries tab
  • Then Double clickon JRE SYSTEM LIBRARY
  • Then select alternate JRE

It should work.

See Also

Upvotes: 3

Related Questions