Here is the list of the most common Java errors we have seen students experience in Mimir Classroom. The list of errors will continue to grow as we learn from students' work and as we hear from instructors like you send recommendations.

control reaches end of non-void function [-Werror=return-type]

This typically indicates that one of your functions was declared to have a return type (non-void function) but it is not returning a value. Check that every non-void function returns the expected value.

ld returned 1 exit status

This error can happen due to a multitude of issues, start by checking that all the required libraries are imported, that all the files names are correct, and that your code compiles (in the case of a project).

stray ‘\342’ in program

This means that one of your double quotation marks are invalid Unicode characters. C and C++ don't allow "smart" quotes (i.e. ” vs "). This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks using your keyboard.

expected ‘;’ before ‘}’ token

This is typically a syntax error. Make sure that for every opening parentheses or bracket there is a matching closing one and that every statement ends with a semi-colon.
You can read more about semi-colons and statements here: http://www.cplusplus.com/doc/tutorial/control/

subscripted value is neither array nor pointer nor vector

This error refers to your use of the subscript operator to access values in an array, pointer of vector. For example, you've declared a single-dimensional array but you're trying access it as a two-dimensional:

int newArray[4];
newArray[4][4] = ...;

no input files

This means the file that the compiler is trying to compile doesn't exist. Make sure the file you're calling exists in the directory you're in and that the extensions are either ".c" or ".h".

expected declaration or statement at end of input

This is typically a syntax error. Make sure that for every opening parentheses or bracket there is a matching closing one and that every statement ends with a semi-colon.

You can read more about semi-colons and statements here: http://www.cplusplus.com/doc/tutorial/control/

suggest parentheses around ‘&&’ within ‘||’ [-Werror=parentheses]

This error is an indication that your if-else conditional statements are missing parentheses. You can read more about if-else statement syntax here: http://www.cplusplus.com/doc/tutorial/control/

unknown type name ‘bool’

Some older versions of C don't allow 'bool' as variable types. If you believe your version of C allows it, make sure you're importing the correct libraries. You can read more about using boolean variables in C here: https://en.cppreference.com/w/c/types/boolean

statement with no effect [-Werror=unused-value]

This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks using your keyboard.

expected identifier or ‘(’ before ‘}’ token

This typically means that the placement of your parentheses and curly brackets is incorrect. Make sure you're using the correct syntax, that your statements end with a semi-colon, and that for every opening parentheses and curly bracket has a closing one.

Read more about C syntax here: http://www.cplusplus.com/doc/tutorial/control/

too many arguments for format [-Werror=format-extra-args]

Typically this refers to the amount and type of arguments passed into a function do not match the expected amount and types in the function declaration.

You can read more about function arguments and syntax here: http://www.cplusplus.com/doc/tutorial/functions/

stray ‘\\222’ in program 

This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks or white spaces using your keyboard.

stray ‘\\210’ in program

This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks or white spaces using your keyboard.

';' expected

This error means that you forgot a semicolon in your code. If you look at the full error statement, it will tell you where in your code you should check within a few lines. Remember that all statements in Java must end in a semicolon and elements of Java like loops and conditionals are not considered statements.

Here is some more information on statements: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/expressions.html

cannot find symbol

This error means that Java is unable to find an identifier that it is trying to work with. It is most often caused by the following:

  1. You misspelled a variable name, class name, or a keyword somewhere. Remember that Java is case sensitive.
  2. You are trying to access a variable or class which does not exist or can not be accessed.
  3. You forgot to import the right class.
illegal start of expression

This error usually occurs when your code does not follow Java's standard structure. Check the nesting of your variables and ensure that all your { } and ( ) are in the right place.

class, interface, or enum expected

This error is usually caused by misplaced { }. All code in Java needs to be contained within a class, interface, or enum. Ensure that all of your code is within the { } of one of those. We often have seen this error when there is an extra } at the end of your code.

Here is some more information on declaring classes: https://docs.oracle.com/javase/tutorial/java/javaOO/classdecl.html

<identifier> expected

This error usually occurs when code is placed outside of a method. Check your { }

Here is some more information on methods: https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html

reached end of file while parsing

This error usually occurs when you are missing a } somewhere in your code. Ensure that for every { you have one } in the right place.

missing return statement

This error usually means one of two things:

  1. Your method is expecting a return statement but is missing one. Ensure that if you declared a method that returns something other than void and that it returns the proper variable type. (image 1)
  2. Your return statements are inside conditionals who’s parameters may not be reached. In this case, you will need to add an additional return statement or modify your conditionals. (image 2)

Image 1:

Image 2:

Here is more information on returning data from methods: https://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html

'else' without 'if'

This error means that Java is unable to find an if statement associated to your else statement. Else statements do not work unless they are associated with an if statement. Ensure that you have an if statement and that your else statement isn't nested within your if statement.

Here is some more information on structuring control flow statements: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/if.html

'(' expected

This error means that you forgot a left parenthesis '(' in your code. If you look at the full error statement, it will tell you where in your code you should check. Remember that for every opening parenthesis '(' you need a closing one ')'.

')' expected

This error means that you forgot a right parenthesis ')' in your code. If you look at the full error statement, it will tell you where in your code you should check. Remember that for every opening parenthesis '(' you need a closing one ')'.

case, default, or '}' expected

This error means that your switch statement isn't properly structured. Ensure that your switch statement contains a variable like this: switch (variable). Also ensure that every case is followed by a colon (:) before defining your case.

Here is more information on structuring switch statements: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

'.class'

This error usually means that you are trying to declare or specify a variable type inside of return statement or inside of a method calls. For example:

"return int 7;" should be "return 7;"

invalid method declaration; return type required

Every Java method requires that you declare what you return even if it is nothing.

"public getNothing()" and "public static getNumber()" are both incorrect ways to declare a method.

The correct way to declare these is the following: "public void getNothing()" and "public static int getNumber()"

unclosed character literal

This error occurs when you start a character with a single quote mark but don't close with a single quote mark.

Here is some more information on characters on other primitive data types: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html


incompatible types

This error occurs when you use the wrong variable type in an expression. A very common example of this is sending a method an integer when it is expecting a string. To solve this issue, check the types of your variables and how they are interacting with other types. There are also ways to convert variable types.

Here is some additional information on data types: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

unclosed string literal


This error occurs when you start a string with a quotation mark but don't close with a second quotation mark. This error can also occur when quotation marks inside strings are not escaped with a backslash.

Here is some more information on strings: https://docs.oracle.com/javase/tutorial/java/data/strings.html

missing method body

This error commonly occurs when you have a semicolon on your method declaration line. For example "public static void main(String args[]);". You should not have a semicolon there. Ensure that your methods have a body.

unreachable statement

This error means that you have code that will never be executed. Usually, this is after a break or a return statement.

while expected

This error means that you have declared a do-while loop and Java cannot detect the while part of the loop declaration. Ensure that you have a while statement and it is properly nested in your code.

Here is more information on do-while loops: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

illegal character: '\\u201c'


This means that one of your double quotation marks are invalid Unicode characters. This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks using your keyboard.

illegal character: '\\u201d'

This means that one of your double quotation marks are invalid Unicode characters. This usually happens when you copy and paste code from other sources or use a text editor that uses Unicode. To fix these error just replace the Unicode quotation marks using your keyboard.

Did this answer your question?