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?
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.
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.
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.
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.
You have a misplaced closing brace before the return
statement.
You have an extra '{' before return type. You may also want to put '==' instead of '=' in if and else condition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With