# Prime Directive: Variable i: cannot find symbol

The error in line 14… ‘i’ has already been defined so i dont understand why the symbol can’t be found.

Error:

Code

``````import java.util.ArrayList;
class PrimeDirective {
public boolean isPrime(int number) {
if (number == 2) {
return true;
}
else if (number < 2) {
return false;
}

for (int i = 2; i< number; i++) ;
{

if (number % i == 0){
return false;
}
return true;
}
}
public ArrayList<Integer> onlyPrimes(int[] numbers){
ArrayList<Integer> primes = new ArrayList<Integer>();
for (int number : numbers){
if(isPrime(number)) {
}
}
return primes;
}
public static void main(String[] args){
PrimeDirective pd = new PrimeDirective();
int[] numbers = {6, 29, 28, 33, 11, 100, 101, 43, 89};
System.out.println(pd.onlyPrimes(numbers));
}
}
``````

It has not been defined. You can show this by defining it, at which point the error goes away.

``````int i = 0;
``````

I suggest writing a separate program that counts from 0 to 9, printing out the number

``````0
1
2
3
4
5
6
7
8
9
``````

why? because that’s the thing you’re currently struggling to do, so looking at it in isolation from the rest will prevent you from getting distracted by any surrounding code (because there is none)
then when you have that functioning you can compare it to what you’ve got (if a problem is too complex to wrap your head around, look at the individual parts in separation from one another)

got it to work, noticed that there is a semi colon behind the for statement - also that the last return true; was in the wrong bracket. but ye, writing out the code in isolation helped since i could confirm it was working up to x point and then compare it.