Search code examples
javacompiler-errorscannot-find-symbol

Receiving Cannot find symbol error, even though everything is declared within the scope


Preface: Sorry if this question has an easy fix, I am fairly new to learning java.

I am trying to compile this block of code, but keep receiving an error stating "Cannot find Symbol" for my for statement, pointing towards 'imp.length().

    public static void main(String[] args) {
    double[] imp = new double[7];
    Scanner lengths = new Scanner(System.in);
    String input = lengths.nextLine();
    String[] inp = input.split(" ");

    try{
        for(int i = 0; i < imp.length(); i++){
            double len = Double.parseDouble(inp[i]);
            imp[i] = len;
            if(imp[i] < 0){
                System.out.println("Invalid Input.");
                break;
            }
        }
    }

I have rewritten the block of code multiple times to ensure that everything is within the correct scope, but I continue to get the same error.


Solution

  • The error is because there is no .length() method of an array, but there is a .length attribute of the array. (No parentheses).