Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the program give "illegal start of type" error?

here is the relevent code snippet:

public static Rand searchCount (int[] x) 
{
    int a ; 
    int b ; 
    int c ; 
    int d ; 
    int f ; 
    int g ;
    int h ; 
    int i ; 
    int j ;
    Rand countA = new Rand () ;
        for (int l= 0; l<x.length; l++) 
        {
            if (x[l] = 0) 
            a++ ;
            else if (x[l] = 1) 
            b++ ;
        }
    }
    return countA ;

}

(Rand is the name of the class that this method is in)

when compiling it get this error message:

Rand.java:77: illegal start of type
        return countA ;
        ^

what's going wrong here? what does this error message mean?

like image 541
David Avatar asked Mar 15 '10 16:03

David


People also ask

What is the error Illegal start of type?

The illegal start of expression java error is a dynamic error which means you would encounter it at compile time with “javac” statement (Java compiler). This error is thrown when the compiler detects any statement that does not abide by the rules or syntax of the Java language.

What does the error illegal start of expression mean?

To sum up, the “Illegal start of expression” error occurs when the Java compiler finds something inappropriate with the source code at the time of execution. To debug this error, try looking at the lines preceding the error message for missing brackets, curly braces, or semicolons and check the syntax.

How do you solve illegal start of expression error?

Missing braces If a brace is omitted, the compiler won't be able to identify the start and/or the end of a block, which will result in an illegal start of expression error (Fig. 4(a)). Adding the missing brace fixes the error (Fig.

How do you solve illegal start of expression in Java?

Move the function declared inside (i.e., bar() ) to an appropriate place outside the outer function (i.e., foo() ). The local variables of a function are only visible inside it and their scope cannot be widened or narrowed. Remove the access specifiers of the variables to resolve this error.


2 Answers

You have a misplaced closing brace before the return statement.

like image 66
codaddict Avatar answered Nov 12 '22 10:11

codaddict


You have an extra '{' before return type. You may also want to put '==' instead of '=' in if and else condition.

like image 27
Neeraj Kumar Avatar answered Nov 12 '22 10:11

Neeraj Kumar