compile time error messages : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

red triangle  compile time error messages
This table contains errors detected at compile time. If you don’t find your error listed here, send me an email at email feedback containing the complete source code so I too can compile it and I will figure out what it means and add it to this list.

Index To Compile Time Error Messages

( expected class should be declared in file not a statement
. expected class, enum or interface expected not abstract
.class expected classname not enclosing class not accessible
; expected Comparable cannot be inherited not found in import
; missing constructor calls overridden method not initialised
= expected constructor used as method operator +
[ expected duplicate class operator ||
already defined duplicate methods package does not exist
ambiguous class enum as identifier permission denied
array not initialised error while writing possible loss of precision
attempt to reference Exception never thrown public class should be in file
attempt to rename final parameter may not be assigned reached end of file while parsing
bad class file generic array creation recompile with -Xlint:unchecked
blank final identifier expected redefined method
boolean dereferenced illegal character reference ambiguous
bound mismatch illegal escape repeated modifier
cannot find symbol illegal forward reference return in constructor
cannot override,
attempting weaker access
illegal reference to static return outside method
cannot override,
does not throw
illegal start return required
cannot override,
incompatible return type
impotent setters serialVersionUID required
cannot resolve constructor incompatible type should be declared in file
cannot resolve symbol instance not accessible statement expected
cannot resolve symbol constructor Thread invalid declaration static field should be accessed in a static way
cannot resolve symbol this invalid flag static not valid on constructor
cannot use operator new invalid label superclass not found
can’t access class invalid method suspicious shadowing
can’t be applied invalid type Tag @see: not found
can’t be dereferenced javac is not a … command type can’t be private
can’t be instantiated; main must be static void type can’t be widened
can’t convert from Object to X method cannot hide type expected
can’t delete jar file method clone not visible type safety
can’t determine application home method matches constructor name type safety: type erased
can’t instantiate abstract class method not found unable to resolve class
can’t make static reference misplaced construct unchecked cast
capitalisation errors misplaced package unchecked conversion
case fallthru missing init unclosed character literal
char cannot be dereferenced missing method body unclosed String literal
clashes with package missing public undefined reference to main
class expected missing return statement undefined variable
class has wrong version missing variable initialiser unexpected symbols
class must be defined in a file modifierr synchronized not allowed unqualified enumeration required
class names only accepted for annotation name of constructor mismatch unreachable statement
class names unchecked only accepted no field unsorted switch
class not found no method found void type
class not found in import no method matching weaker access
class not found in type declaration non-final variable { expected
class or interface declaration expected non-static can’t be referenced } expected

Compiler Error Messages

Compiler Error Messages
Key What Compiler Says
Real Error / Possible Causes
( expected ( expected instead of {.
// oops missing [] in attempt to define an array literal
new String { "x", "y" };
instead 
// how to create string array literal
new String[] { "x", "y" };
See balancing.
. expected '.' expected. Usually pointing to an import statement.
You must import either a packagename.* or packagename. Classname. You can’t just import packagename or import Classname. You don’t import classes in the same package as the current class. In other words, the thing you import will always contain at least one .. You don’t use import for code not in any package. You have to put such classes on the classpath. Whenever you have more than one class, it is a good idea to assign every class to an explicit package with a package statement. In summary, you import fully qualified classes, with package and classname separated by a dot. You don’t import classes without packages.
.class expected '.class’ expected
you wrote int i where you meant just plain i.
; expected semicolon expected.
  • Usually this is just a missing semicolon,
  • sometimes it can be caused by unbalanced () on the previous line.
  • sometimes it can be cause by junk on the previous line. This junk might be far to the right off the screen.
  • Sometimes it is caused by spelling the keyword if incorrectly nearby.
  • Sometimes it is a missing + concatenation operator. C programmers often make this one on multi-line Strings since the concatenation operator is implied in C.
; missing ';' expected. 'else' without if. statement expected. invalid expression.
missing semicolon. See ; expected.
= expected = expected.
Look for a stray } just before where it is complaining.
[ expected Missing [
Likely you wrote [i,j] instead of [i][j].
already defined Variable 'x' is already defined in this method.
duplicate variable declaration
ambiguous class ambiguous class x.y.SomeClass and a.b.SomeClass,
reference to Object is ambiguous, both class org.omg.CORBA.Object in org.omg.CORBA and class java.lang.Object in java.lang match.
// Ambiguous Class import.
// If you were to use SomeClass, which one did you mean?
import x.y.SomeClass;
import a.b.SomeClass;
can 
// Ambiguous Class import for x.y.SomeClass and a.b.SomeClass
// but the compiler won't mind unless you actually use SomeClass.
import x.y.*;
import a.b.*;
Some compilers may complain about the clash in SomeClass, even if you never reference it. And, of course, all references to SomeClass should be disambiguated to either x.y.SomeClass or a.b.SomeClass. Alternatively, you can throw out all the imports and fully qualify all classes in x.y and a.b. This approach makes code easier to maintain because it is easier to find the code that implements the class when it is fully qualified. In your own classes, try to use globally unique class names. Even if the computer understands the ambiguity, humans often become confused.
array not initialised Array a may not have been initialized.
You forgot to initialise an array with new int[5].
attempt to reference Attempt to reference method xxx in class XXX as an instance variable.
missing dummy pair of parentheses after the 0-argument method name.
attempt to rename jarsigner: attempt to rename xxx.jar to xxx.jar.orig failed.
Your jar is in use by some running Applet or application. Shut it down to build and sign the jar.
bad class file bad class file: XXX.java file does not contain class XXX. Please remove or make sure it appears in the correct subdirectory of the classpath.
Check that the package statement and the class statement have names that are precisely correct including case and that this file is in a directory that precisely matches the package name and the source file name that precisely matches the class name followed by .java.
blank final Blank final variable 'xxx' may not have been initialized. It must be assigned a value in an initialiser, or in every constructor.
Check that your final variable is indeed so initialised. If it is, remove the final, to bypass a bug in the Javac 1.1 compiler.
Boolean dereferenced Boolean cannot be dereferenced.
You need extra layers of parentheses around your casting.
Bound mismatch Eclipse error: Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for the arguments (ArrayList<X>). The inferred type X is not a valid substitute for the bounded parameter <T extends Comparable<? super T>>
You forget to implement Comparable on the class X you are sorting.
can’t access class Can’t access com.mindprod.mypackage.MyClass. Only classes and interfaces in other packages can be accessed.
  • You forgot to make the class public.
  • In JBuilder, check the properties for your project. Your root directories should be plain C:\ not J:\com\mindprod\thepackage\
can’t be applied setVisible(Boolean) in java.awt. Component cannot be applied to ()
You wrote x.setVisible() instead of x. setVisible( true ), or similar parameter mismatch. Check the types of parameters and arguments for an exact match. Whenever you see cannot be applied check the Javadoc to make sure the signature of the method you are calling matches the types of the arguments. The problem often is you are sure a method must logically have to exist that does not.
It ain’t what you don’t know that gets you into trouble. It’s what you know for sure that just ain’t so.
~ Mark Twain (1835-11-30 1910-04-21 age:74)
can’t be dereferenced int cannot be dereferenced.
You need extra layers of parentheses around your casting. or perhaps you may have written something like i.toString() where i is an int rather than an object with methods. You need to write something like  Integer.toString( i) instead. ints can’t have any instance methods. They can be parameters to either static or instance methods though.
can’t be instantiated; load: com.mindprod.mypackage.MyApplet.class can’t be instantiated. java.lang.InstantiationException: com/mindprod/mypackage/MyApplet
You are missing the default constructor for your Applet. See The Case of the Disappearing Constructors.
can’t convert from Object to X Type mismatch: cannot convert from Object to X.
This error often comes up in the context of the clone method which, without covariance, returns an Object reference not the specific type of the Object cloned as you might naïvely expect. You tried to use a general Object reference in a context that requires something more specific. Sometimes all you need is a cast.
can’t determine application home Can’t determine application home.
Uninstall all Java JDKs (Java Development Kits) and JREs (Java Runtime Environments) with the Control Panel. Use Microsoft’s RegClean. Tidy up the registry with regedit. Reinstall just the latest JDK (Java Development Kit).
cannot find symbol Cannot find symbol
You used a variable name you did not define. Perhaps you forgot the declaration. Perhaps you declared it inside a block/loop and you tried to use it outside the block/loop. You must move the declaration to an encompassing outer block that encloses all the references. Perhaps you spelled the variable slightly differently in declaration and reference. Watch your caps and double letters carefully. Perhaps you left out or mistyped the corresponding import or static import.

Cannot find symbol constructor XXX, means you likely you did an explicit XXX() to call the superclass constructor first thing in your constructor instead of using super().

Cannot find symbol method XXX, where XXX is your class’s superclass constructor means you likely you did an explicit XXX() to call the superclass constructor first thing in your constructor instead of using super().

Possible causes of the error for constructors and methods:

  • Wrong syntax for calling: constructor: new X(), instance: x. someMethod(), static: SomeClass.someMethod ().
  • The method you want is protected or private.
  • You left out a parm.
  • You added an extra parm.
  • You have the parms in the wrong order.
  • You have the type of a parm wrong, e.g. it wants a File, but you gave it a String.
  • Symbols are case-sensitive. You have a mismatch.
  • Confused package. Javac.exe is looking in the wrong package or class, e.g. java.util.List vs java.awt.Listawt.List. Use fully qualified references to rule that out.
  • The referenced class did not compile because it has a syntax error.
  • The needed class/jar files are not on the classpath.
  • Cannot find symbol method sort(java.util.ArrayList<Xxx>) could mean you have not implemented Comparator on the class you are trying to sort.
  • There is some other syntax error, than the compiler interprets its strange way as an undefined symbol.
Using the -verbose option on javac.exe will give you hints to help resolve this error. Cannot Resolve Symbol
can’t instantiate abstract class Error: MyClass is an abstract class. It can’t be instantiated.
missing method to fulfill an interface implementation
can’t make static reference Can’t make a static reference to non-static (instance) variable x in MyClass.
using an instance variable in a static method
cannot override toString() in xxx cannot override toString() in java.lang.Object; attempting to assign weaker access privileges; was public.
You can override a default or protected method with a public one, but not the reverse.
cannot override toString() in xxx cannot override toString() in java.lang.Object; overridden method does not throw java.io.IOException
Overridden methods cannot add any throws clauses not in the base method they are overriding.
cannot override cannot override xxx() in java.lang.Object; attempting to use incompatible return type.
When you override an existing method, you must use exactly the same method signature including return type. Perhaps you did not realise you were overriding a method. In Java version 1.5 or later, you may return a subclass of the base return type.
cannot resolve constructor Cannot resolve constructor xxx().
If a subclasses constructor does not call one of the constructors of the superclass as the very first thing, java inserts a call to the default constructor for you super(). If you have not defined that null constructor, you will get an error. The usual way to fix it is by inserting some sort of super( parm ); as the first statement of your subclass constructor. See also hints on resolving symbols.
cannot resolve symbol Cannot resolve symbol
  • No such variable or method. Perhaps it exists, but not in the current scope, e.g. you are trying to use a variable defined inside a loop outside that loop.
  • Possibly you are trying to use a constructor without new as if it were an ordinary method.
  • You left off the () on your method call.
  • If the error message is pointing to code that uses the standard classes, chances are you either misspelled it, or forgot to import the class, or misspelled the import. If it is pointing to one of your methods or variables chances are you misspelled it either in the definition or reference. Java is picky. You must get upper-lower case precisely correct too.
  • If the code is pointing to one of your classes that is clearly there, perhaps you forgot to put C:\ on the classpath — the mother of all packages where com is in com.mindprod.thispackage lives. If you are not using packages, perhaps you forgot to put. on your classpath. A symptom of this is you can compile successfully if you rebuild everything, but not if you just recompile the changed modules.
  • You are using a method of the object when the reference is to an interface that does not contain that method. Either cast to specific object, or change the reference to a specific object reference, e. g. addNever is a method of MultiFilter, but not of FileNameFilter.
  • Watch for subtle spelling differences between declaration and reference, e.g. Hashtable and HashTable. Copy/paste the definition on top of the reference to be sure they are absolutely identical. Your eyes can fool you.
  • In an implements clause, you may have used a period where you should have used a comma.
  • If is complaining about the superclass of your constructor, the problem is you must either explicitly call super(), or there must be a superclass constructor with a matching signature.
  • Cannot Find Symbol
cannot resolve symbol constructor Thread cannot resolve symbol constructor Thread( YourRunnable )
You forgot to write implements Runnable on the class with the run method.
cannot resolve symbol this Cannot resolve symbol this.xxx
You are inside an anonymous inner class and xxx is a member or method of the enclosing class. You must use Outer. this. xxx instead of this.xxx.
cannot use operator new Cannot use operator new for this type
You can’t instantiate references, class names as Strings, interfaces or abstract classes, only concrete class names. Perhaps there is no suitable constructor. Perhaps you inadvertently wrote methods instead of constructors by specifying a return type on them.
can’t delete jar file Ant complains it cannot delete the jar file during a build
You are running the application from the old jar. Shut it down before rebuilding.
char cannot be dereferenced char cannot be dereferenced
You have tried to use a String or other Object method on a char or char[] which have no instance methods.
clashes with package XXX clashes with package of same name
Rename your class or rename your package so they don’t have the same name. Usually this is not a problem since package names normally have dots in them.
class has wrong version class file has wrong version 49.0, should be 48.0
You are compiling with the Java version 1.4 compiler, referencing class files compiled with the newer  Java version 1.5 compiler. The referenced class files must be recompiled with 1.4 to make them compatible with the old Java. Alternatively, you must use JDK 1.5 for everything.
class must be defined in a file Warning: ublic MyClass must be defined in a file called 'MyClass.java'.
  • class name does not match source filename.
  • Putting more than one public class per file.
  • Getting the capitalisation wrong in the filename on the javac command line or in the filename itself.
class names only accepted for annotation processing Error: Class names, 'XXX', are only accepted if annotation processing is explicitly requested

There is nothing wrong with the text of your program; the problem is in how you tried to compile it. You left off the *.java extension when compiling with javac.exe, e.g. at the command line you typed:

javac.exe MyClass

instead of:

javac.exe MyClass.java
This is one of the most maliciously misleading of all error messages.
class names unchecked only accepted for annotation processing error: Class names, "unchecked", are only accepted if annotation processing is explicitly requested
For Netbeans, uncheck the project’s property entitled Enable Annotation Processing in Editor, leaving all others checked on that page and clean and build the project.
class not found Class not found
This can occur at compile or run time.
  • You are using Internet Explorer which has a defective or missing Java.
  • Some other syntax error ahead of the class declaration is preventing the compiler from seeing the class declaration.
  • The class is not in the proper file in the proper directory.
  • The class is not public.
  • The class does not have the correct case, either in the class name or the file name.
  • The corresponding class or java file is not on the CLASSPATH (considering the package name.)
class not found in import class com.mindprod.mypackage.Myclass not found in an import
All class files and packages you reference in import statements must be accessible via the CLASSPATH, or be part of the project or live in the ext directory. You must import a class, not a package, e.g. import java.io.File ; not import java.io; You can import all the classes in a package with: import java.io. *; It is easiest to use an IDE (Integrated Development Environment) like IntelliJ that inserts and prunes the imports for you. Also remember that package and class names are case-sensitive.
class not found in type declaration Class WindowAdapter not found in type declaration.
You forgot to import java.awt.event.* or to fully qualify java.awt.event.WindowAdapter. I’m sure you can generalise for other classes.
class expected class expected.
It is not expecting the keyword class, but rather the name of a class. You might have written something like long.MAX_VALUE instead of Long.MAX_VALUE.
class or interface (or enum) declaration expected class or interface (or enum) declaration expected.
  • Put your package statement before all the imports. The imports come before your class declarations.
  • Make your class public, not protected.
  • You may have too many } so that you have finished off your class before you intended too. Using a source code beautifier that aligns code block and {} will help make these sorts of errors obvious.
class, enum or interface expected class, enum or interface expected
There is a missing { somewhere much earlier in the code. class and interface must be all lower case. Another way of looking at it, you method and variable definitions come after class, not package.
class should be declared in file class XXX is public, should be declared in a file named XXX.java
The name of the *.java file must precisely match the name of the public class it defines. The name is case-sensitive.
classname not enclosing class classname is not an enclosing class
  • You are attempting to instantiate a non-static named inner class without an instantiated the outer class. Solution: declare the named inner class as static or instantiate your inner class like this as described under nested classes.
  • You used an expression like JApplet.this in an inner class. You must specify the precise name of the enclosing class, e.g. MyApplet. this not one of its superclasses. If you wanted a superclass reference you would have to use (JApplet) MyApplet. this.
Comparable cannot be inherited Comparable cannot be inherited with different arguments
// base class
class SalesTaxItem implements Comparable<SalesTaxItem>
{
...
}

The best way I know of to bypass the problem is to write both classes without the implements Comparable. Then write two Comparators instead.

duplicate class Duplicate class
You misspelled the package name on the package statement. It must match the name of the directory containing the Java source.
duplicate methods duplicate method declaration
You have two methods with the same name and the same signature i.e. number and types of parameters. You can’t have two methods that differ only in return type.
enum as identifier try -source 1.4 or lower to use 'enum' as an identifier.
Starting with Java version 1.5, enum became a reserved keyword. Older programs may have used the word enum as a variable, method or package name. You will have to globally rename enum to some other identifier, or convert the code to use the new built-in enum features.
error while writing error while writing <classname>. The system cannot find the path specified.
You used the javac.exe -d option. The compiler is trying to write the generated class files to this directory, but it cannot, probably because it does not exist. The compiler wants to create a tree of package names in that directory. You may have it blocked by files of the same name as the packages. Use lower case for all package names and directories.
Exception never thrown Exception IOException is never thrown in the body of the corresponding try statement.
You are trying to catch an exception that could never happen. Just remove the try/catch. Java does not like you trying to catch an exception that could never happen, but oddly it does not mind you declaring a throws that could never happen.
final parameter xxx may not be assigned Attempt to assign to a variable declared as final
The wording is ambiguous. You might think it means the parameter might, under some circumstances, escape being assigned. That is not what it means.
generic array creation Attempt to create an array of generic objects

You might have written new ArrayList <String>[ 100] instead of new ArrayList< String>( 100);

To be charitable, Java’s generics are Mickey Mouse. One of the side effects of the el-cheapo implementation is that you can’t have arrays of generic collections, e. g. the following is illegal

identifier expected identifier expected
Look for a missing { slightly before of where it is complaining. It may also be a } before the code that should appear after. It can also be caused by attempting to define a constructor in an interface. Perhaps you wrote some initialisation code without enclosing it in static {} or plain {}. Method calls must be inside methods or init blocks, not just lying loose in amongst the field declarations.
illegal character illegal character: \8220 or \8221
You used Unicode 8220 (aka \u291c, 0x291c, “, left quote) or 8821 (aka \u291d, 0x291d, ”, right quote) instead of a simple 34 (aka \u0022, 0x22, ") that Java requires. This probably resulted from using a word processor like MS Word instead of a text processor or IDE to compose your Java source which converts "s into and .
illegal escape illegal escape character
Mostly likely you forget to double each \ in a filename String, e. g. you should write C:\\temp\\somefile.txt not C:\temp\somefile.txt. Backslash \ has special meaning inside Strings, e. g. \n means newline, \t means tab, \" means embedded ". \\ means a single \. If you used \ followed by a letter without special meaning, you will get this error message.
illegal forward reference Probable forward enum reference

Java computes its static initialisation in a simplistic top to bottom way. It is not clever, in using natural order like a spreadsheet. Any value you reference must be defined lexically earlier in the class. This holds both for the order of initialisations and for the order of assignments in a static init or instance init block.

  • You may not reference an enum constant that has not yet been defined. e.g. you cannot reference other enum constants in an enum constructor call.
  • You must declare static finals before you define them in a static init block. Put your static init blocks after all your static final variables.
  • You must define the value of a static final before you can use it in defining the value of another static final.
illegal reference to static illegal reference to static field from initialiser
enum constructors cannot access the enum static fields. However, they can invoke the enum’s static methods that access the static fields, but they won’t get the right values. The easiest way out is to convert your static constants to instance constants. Strange as it seems, they are initialised before the constructor code. Constructors may, however, directly access static final in-lineable constants known at compile time.
The problem is static initialisation has not been done at the time the enum constructor constant constructors are invoked, so static methods called from your constructors will just see zeros/nulls. Why this screwy rule? You’d think statics would be initialised first, the way they are with any other classes. The JLS (Java Language Specification) justifies it this way:
The direct superclass of an enum type named E is Enum<E>. In addition to the members it inherits from Enum<E<, for each declared enum constant with the name n the enum type has an implicitly declared public static final field named n of type E. These fields are considered to be declared in the same order as the corresponding enum constants, before any static fields explicitly declared in the enum type. Each such field is initialized to the enum constant that corresponds to it. Each such field is also considered to be annotated by the same annotations as the corresponding enum constant. The enum constant is said to be created when the corresponding field is initialized. The direct superclass of an enum type named E is Enum<E<. In addition to the members it inherits from Enum<E<, for each declared enum constant with the name n the enum type has an implicitly declared public static final field named n of type E. These fields are considered to be declared in the same order as the corresponding enum constants, before any static fields explicitly declared in the enum type. Each such field is initialized to the enum constant that corresponds to it. Each such field is also considered to be annotated by the same annotations as the corresponding enum constant. The enum constant is said to be created when the corresponding field is initialized.
~ Java Language Spec
In other words, the gotchas is a side effect of the kludgy way enums are implemented.
illegal start illegal start of expression
  • The error message will point to perfectly good code. Look just ahead of it for a missing } or ;
  • static int x = 0; Static variables have to be defined outside all methods inside a class.
  • you wrote x + = 2; instead of x += 2; You also may have used an ) when you meant a }.
  • you wrote case: STRAWBERRY instead of case STRAWBERRY :
  • You nested a method inside another method.
incompatible type Incompatible type for =. Explicit cast needed to convert int to byte.
missing a cast such as (byte)
instance not accessible Error: An instance of XXX.this is not accessible here because it would have to cross a static region in the intervening type XXX.
Something is wrong with the parameters to an inner class.
invalid declaration Invalid declaration
Most likely the name you are trying to declare is invalid. It must not contain dots. It must not start with a digit.
invalid label invalid label
You used a semicolon instead of a colon after a label.
invalid flag javac: invalid flag: MyClass
writing javac.exe MyClass or javac.exe MyClass.class instead of javac.exe MyClass.java.
invalid method Invalid method declaration; return type required.
forgetting void return type on a method declaration. Possibly your constructor and its class name do not match exactly, including case.
invalid type Invalid type expression.
You forgot the semicolon.
javac is not a … command javac is not an internal or external command operable statement or batch file
J:\Program Files\java\jdk1.8.0_131\ \bin\javac.exe must be on the path. See JDK for details on polishing and testing your JDK installation.
main must be static void main must be static and void
An application’s main class must have a method public static void main (String[] args).
method cannot hide The static method XXX declared in class AAA cannot hide the instance method of the same signature declared in class BBB (Better Business Bureau). It is illegal to hide an instance method.
You can’t use the same name for a static and instance method in a subclass. Either you have to give them different names, or make them both static or make them both instance, or change the signature (parameter types) to make them different.
method clone not visible The method clone() from the type Object is not visible
If the class containing clone is one of yours, you must implement a public clone method, that will probably use the protected version in its implementation. If the class is built-in, unfortunately, it does not have a public clone method, just a protected clone, which you may not use, unless you write a class extending the built-in class. See clone for details.
method matches constructor name The name of this method XXX matches the name of the containing class. However, the method is not a constructor since its declarator is qualified with a type.
You can’t put void on a constructor, or put any other return type for that matter.
method not found Method MyClass() not found in MyClass
  • undefined (missing) method.
  • You wrote MyClass x = MyClass(); instead of MyClass x = new MyClass();
misplaced construct misplaced construct
  • You wrote doSomething( String[] choices ) rather than doSomething( choices )
  • There is a stray } just before of where it is complaining.
misplaced package Error: com/sun/java/swing/xxx is either a misplaced package name or a non-existent entity.
Sun renamed com.sun.java.swing to javax.swing but your code is still using the old name. Use a global search and replace on all your *.java files.
missing method body missing method body, or declare abstract
You inserted a semicolon just before the first { of a method.
missing return statement missing return statement
No matter how control flows through your method, it must end with a return statement, unless the method has a void return. The most common failing is when you catch an exception. The return in the try body conceptually might never be executed because of an exception potentially being triggered. You need a return in the catch block or after the catch block too. Javac is not as clever as you. You may be sure the exception will never dodge the return in the try block, but javac can’t be so sure.
modifier synchronized not allowed modifier synchronized not allowed here
synchronized applies to methods and blocks of code. transient applies to variables.
name of constructor mismatch The name of the constructor main does not match name of class MyClass
You forgot your return type, e.g. void, on a method.
no field No field named length was found in type java/lang/String
You said s.length rather than s.length() to get the length of a String. The a.length form without the () is only used for arrays. Whereas Lists (e.g. ArrayList) use java.util.List.length(). Collections use Collection.size() just to keep you on your toes. You will even see getLength() every once in a while. The designers of Java must hate newbies to put such stumbling blocks in front of them. It is either laziness of a subtle form of one upmanship.
no method found No method xxx found in class yyy.
You have the wrong number of parameters or the wrong parameter types for the method. It can also mean you defined a method with the wrong visibility modifier, e.g. none, private or protected when you meant public. Perhaps you called it as if it were static and defined it as instance, or vice versa. Perhaps you were calling a constructor without new.
no method matching No method matching myMethod() found in MyClass
You have the wrong number of parameters or the wrong parameter types for the method. It can also mean you defined a method with the wrong visibility modifier, e.g. none, private or protected when you meant public. Perhaps you called it as if it were static and defined it as instance, or vice versa. Perhaps you were calling a constructor without new.
cap missing no warning. caps missing.
  • missing caps on a class name declaration.
  • Caps on a variable/method declaration
impotent setters no warning. impotent setters.
  • this.x = x; Effectively you wrote this.x = this.x; because there is no x parameter.
  • // This method does nothing,
    // just sets this.brush to itself.
    // Note misspelling brash for brush.
    // No warning!
    // Eclipse compiler will warn you though.
    public voidsetBrush ( int brash )
       {
       this.brush = brush;
       }
missing public no warning. missing public.
In debug mode, if you forget to make your main method public, you will not be warned. You won’t discover the problem until later. main must be public static void.
case fallthru no warning. Case fall through is the default.
missing break. In Java version 1.4 or later you can use the javac.exe -Xswitchcheck to get this error detected.
missing initialisation no warning. Missing initialisation.
  • The array is automatically initialised to null. This will likely soon lead to a java.lang.NullPointerException when you try to apply some method to one of the elements of the array. Note Null PointerException, not NullReferenceException. You forgot to initialise an array of strings or objects to some value.
  • You forgot to initialise an int array to some value or populate it with objects.
missing variable initialiser missing variable initialiser
Don’t put () around the dot-separated parts of a name.
constructor treated as method no warning. Constructor treated as a method.
specifying a void return type on a constructor. Method with the same name as the class.
suspicious shadowing no warning. reusing instance variable as local.
You accidentally declared a local variable with the same name as an instance or class variable when you intended to use the instance or local variable. This is my most common error that the compiler does not detect. The Jikes compiler will warn you of this.
calling overridden methods in constructor no warning. calling overridden methods in constructors
Be very careful calling any methods inside your constructors. If subclasses override them, you will be invoking the subclass’s version, which may be attempting to use fields that have not been initialised yet. You won’t get a warning message! The problem usually shows up as puzzling NullPointerExceptions. The way out is to move code out of the constructor, often to the addNotify method. However, addNotify can get in analogous problem to the constructor since it too is overridden and it may use overridden methods.
non-final variable local variable xxx is accessed from within inner class; needs to be declared final or cannot refer to a non-final variable xxx inside an inner class defined in a different method.
Inside anonymous classes, you can’t use local variables of the enclosing method unless they are final. I don’t mean instance or static variables. I don’t mean passing locals as parameters to the anonymous constructor. I mean directly accessing local method stack variables directly from anonymous inner class methods. When you do that, they variables have to be final. more details.
non-static can’t be referenced non-static method xxx cannot be referenced from a static context
  • In a static method, you used an instance method without an object, e.g. MyClass.xxx(). You must first create an object with MyClass o = new MyClass();, then use o.xxx(); to invoke the method.
  • You used an instance variable (one without the static attribute) inside a static method. static methods don’t have access to any particular object, so can’t use any of the instance (per object) fields. You may have used a reference to an inner class inside a static method. Make that inner class an ordinary separate class. Inner classes are always linked to an instance of the main class. You may have tried to instantiate an inner class in some static code. You need to make the inner class static to be able to use it without a mother object.
  • You tried to access an instance variable or method of the outer class from static nested class.
  • You tried to instantiate/reference a non-static inner class from a static method of the outer class. Either make the inner class static, or make it an independent class, or make the invoking method an instance method.
  • This sounds bizarre, but you were using an enum with some enum private methods. Remove the private keyword and magically all will work. Use an IDE like IntelliJ Idea to show you will methods can be private. This is a side effect of the way enums are implemented. enum constants with a body of their own methods are implemented as anonymous inner classes defined in a static init block. They can’t access the private methods of the mother class. The error message is misleading. The problem is one of scope, not context.
not abstract SomeClass is not abstract and does not override abstract method someMethod.
You defined a class that extended an abstract class, but you forgot to provide a concrete implementation for one of the abstract methods.
Check out all the abstract methods in the base abstract class and make sure you have provided implementations for all of them of them.
not a statement Not a statement
  • The compiler was expecting a statement and you gave it something else, e. g. you wrote if (i > 7) 42;. You might have used a variable name beginning with a digit or punctuation or some other improper character.
  • Perhaps you used == instead of = in an assignment statement, turning it into an expression instead of a statement.
  • you wrote x + = 2; instead of x += 2;
  • Perhaps you had a stray semicolon in a statement made of dozen of concatenations.
not accessible xxx.this is not accessible here because it would have to cross a static region in the intervening type.
Move your named inner class definition outside a static method. Keep in mind, instances of inner classes must be associated with an instance of the main class. As a corollary of this, you can’t create anonymous inner classes except inside instance methods.
not found in import not found in import.
The package you mentioned is not available on the classpath. Make sure you spell it with proper case. Make sure you understand the limitations of import wildcards. See import, classpath.
not initialised Local variable x may not have been initialized. There is some execution path from the declaration of x to where you used its value, that avoids setting its value. It often involves an exception.
missing initialisation for a temporary variable. If you initialise it in a try block, you need also to initialise it in the catch or before the try in case you get an exception.
operator + operator + cannot be applied java.lang.String
Irritatingly, Java does not allow unary + in front of a String, only between Strings so you can’t write 
operator || operator || cannot be applied to int,int
you wrote if ( x1 = x2 || y1 = y2 ) instead of if ( x1 == x2 || y1 == y2 )
package does not exist Package Java.Applet does not exist.
  • Java is case-sensitive. The package is called java.applet, not Java.Applet. Package names are supposed to be pure lower case.
  • Check that the package is available on the classpath or in some jar in the appropriate ext directory. You can use winzip to examine the jar file directories to find out which classes they contain. To help discover which jar does contain your class use Google on the package name + jar. Then get that jar on the classpath or in the ext directory.
  • This error can so come up when you try to allocate an inner class object, e.g.
    import java.awt.geom.Ellipse2D;
    
    ...
    
    // allocate an inner class Float object of the Ellipse2D class
    return new Ellipse2D.Float( x,  y,  w,  h );
    You should use an import for the outer class. You don’t need to import the inner, though you may optionally do so. Don’t try to use * notation to import the inner class..
Permission denied error while writing XXX: XXX.class (Permission denied)
This will happen in Linux/Unix systems, particularly if you use the Javac.exe -d targetdir option. You are trying to write your generated class files to a directory where you don’t have permission, or the *.class files that you are overwriting may have been generated with a different owner.
possible loss of precision possible loss of precision
You did something like i = d; where i is an int and d is a double. Narrowing will throw away high order bits or the fraction. You need an explicit cast to acknowledge this loss, e.g. i = (int)d;
public class should be in file public class Xxx should be in a file named Xxx.java.
Javadoc.exe is particularly picky about case. Make sure the name of the class exactly matches the name of the file and that the name of the package exactly matches the name of the directory tree, e.g. com.mindprod.mypackage.MyClass should be in a file called com\mindprod\mypackage\MyClass.java or com/mindprod/mypackage/MyClass.java, exactly including case of the directory names.
reached end of file reached end of file while parsing
This is usually a brace balancing problem. You are missing a closing brace, so the parser got to the end while it figured it was still inside the class. The problems can also be caused by unbalanced " and unclosed comments. IDEs (Integrated Development Environments) often have tools to help you balance braces. Code tidiers make unbalanced braces more obvious. For tough case try the BraceBalancer applet/utility.
method already defined valueOf(java.lang.String) is already defined
There are two causes, one is you simply defined the same method with identical signatures, or signatures differing only in return type in the same class. The other you tried to override the valueOf method in an enum class. There is already a generated hidden implementation in your class, so you can’t override it. Use some other name. The same applies to the automatically constructed methods, compareTo, ordinal and equals.
Recompile with -Xlint:unchecked XXX uses unchecked or unsafe operations. Recompile with -Xlint:unchecked for details
You used a Collection without generifying it. If it is not obvious what the problem is, recompile with javac.exe -Xlint:unchecked *.java
reference ambiguous reference to xxx is ambiguous, both method xxx(java.lang.String) method xxx(java.lang.Object) match xxx(null). You have two methods with similar signatures. When you call a method with null, there is no type information to help the compiler decide which version to use. Use a typed constant whose value is null.
repeated modifier repeated modifier
You specified a modifying keyword more than once e.g. final or public.
return in constructor 'return' with value from constructor: MyClass(..).
specifying a return this in a constructor
return outside method return outside method
you have a return dangling between classes. Perhaps you left the ; before the method {body} in when you converted from abstract method to a real one.
return required Return required at end of MyClass Myclass(..).
specifying a MyClass return type on a constructor
serialVersionUID required serializable class XXX has no definition of serialVersionUID
Assign your class a serialVersionUID
/**
 * Defining a layout version for a class.
 * Watch the spelling and keywords!
 */
public static final long serialVersionUID = 3L;
should be declared in file Could not find the main class. Program will exit.
There is a problem with the Main-Class entry of manifest in the jar file. Possibly you got the package name wrong or the case of the name off. The Main-Class must exist in an element of the jar filed under the package name as the folder. Possible the Class you specified is missing a public static void main(Strings[] args) method. Check the gotchas in setting up the manifest.
statement expected Statement expected.
missing } in a method
static not valid on constructor static is not a valid constructor modifier
You forgot your return type e.g. void, on a method.
static field should be accessed in a static way. The static field Calendar.HOUR_OF_DAY should be accessed in a static way.
You specified c.HOUR_OF_DAY where c is a Calendar instance reference. You should get at the static constant with Calendar. HOUR_OF_DAY.
Tag @see : reference not found Must have a class or method signature
You should have something of the form @see java.lang.String or java.lang.String#indexOf(char). Most commonly you have left off the parameters on a method. The target must be in the standard System Javadoc or in the Javadoc bundle. You can’t point to a class whose Javadoc is not in the bundle.
superclass not found Superclass YYY of class XXX not found.
Did you remember to import the YYY class?
type can’t be private The type MyClass can’t be private. Package members are always accessible within the current package.
Top level classes can’t be private, only classes nested inside others.
type cannot be widened the type of this expression, 'double', cannot be promoted to 'int' by widening conversion.
Java cannot automatically convert a double to an int. There are many options. See Converter Amanuensis for the code you need.
type expected Type expected. identifier expected.
  • extra }, or literally a missing type, especially in constant declarations like: public static final SOMETHING=3; instead of public static final int SOMETHING=3;
  • Executable code has to be inside some method, in a static initialiser block or in an instance initialiser block. It can’t be just dangling inside a class or outside any class. Check that your {} are balanced. Code you think is in a method may actually be outside because of an extra unbalanced }.
type safety Eclipse error: Type safety: Unchecked invocation sort(List<X>) of the generic method sort(List<X>) of type Collections X
You forgot to generify your X implements Comparable<X> and similar differences for generics documented under Comparable.
type safety: erased type Type safety: The cast from Object to ArrayList<String> is actually checking against the erased type ArrayList.
The compiler is warning you that the cast you are doing is only ensuring the Object is an ArrayList. It can’t tell if it truly is an ArrayList< String>. If it isn’t, on your head be it. If it is not really an ArrayList< String> expect a ClassCastException as soon as you do a get, even though there are no explicit casts near the get in your code. The problem in essence is that serialized objects contain no record of their generic type. Many think that design decision was a big mistake.
unable to resolve class anable to resolve class: xxxx
This happens when genjar is building a jar. It can be caused by a missing class file that is needed for the jar, but more frequently is just happens for no apparent reason. You can try rebooting is case the problem is some other application has the needed class file locked. Earlier versions of genjar did not even tell you which class file it was having trouble with.
unchecked cast warning: [unchecked] unchecked cast
This is a subtle problem. The root cause of it is type erasure. All information the compiler has about generics is erased from the run time. You did a run-time cast that would require the run time to have knowledge of the generic information. In Java version 1.5 or later, you can use a @SuppressWarnings to pat the compiler on the head and say There there. I know what I am doing. Not to worry.
unchecked conversion Warning: [unchecked] unchecked conversion
You used a Collection without generifying it. If it is not obvious what the problem is, recompile with javac.exe -Xlint:unchecked *.java
unclosed character literal unclosed character literal
Single char literals are enclosed in ’s. Strings, including empty and 1-character Strings are enclosed in "s. You may have used an invalid representation for a char literal. You may have tried to put a string of more than one character between the 's. char literals that need quoting include: '\"', '\'', '\n' and '\\'.
unclosed string literal unclosed string literal
String literals are enclosed in " characters. Check the lead and trail character to make sure it is indeed a " not something similar looking. Check for awkward characters (e.g. " ' \ ) embedded in the string and make sure they are preceded by a \. For a string made up of pieces, make sure there is a + between each pair.
undefined reference to main undefined reference to main with gcj.
If you are using the gcj Java compiler, you left off the --main command line option or you screwed it up in some way. It needs the fully qualified name of your main class, which will necessarily have a public static void main method.
undefined variable Undefined variable x; or Variable x in SomeOtherClass not accessible from MyClass Incompatible type for =.
  • caps on a variable reference
  • missing variable declaration
unexpected symbols Unexpected symbols ignored.
You just coded a snippet. All code has to live inside a method and all methods have to live inside a class. The only exception are static and instance initialisers, which must be contained in {} inside a class.
unqualified enumeration required unqualified enumeration constant name required
This is the Java version 1.5 or later enum type checking catching you. Your enum constant on a case is not of the same type as the variable in the switch.
unreachable statement statement unreachable
You have written some code that could never be executed, e.g. you put some code immediately after a throw or return statement.
unreported exception Unreported exception java.text.ParseException; must be caught or declared to be thrown.
The code potentially throws an exception. You must either wrap it in a
try {…}
catch (ParseException e) {…}

or put a throws declaration on the method to let the caller deal with it.
unsorted switch Unsorted lookup switch
Java won’t let you have two different symbolic constants as case labels if they have the same numeric value, even if they label the same block of code.
void type 'void' type not allowed here
You are using a method that does not return a value in a place where a value is required such as the right side of an equal sign or a parameter to another method.
weaker access Attempting to assign weaker access privileges; was public.
The original method you are overriding was public. Your overriding method must be public too. This often happens when you implement a method in an interface. All methods in an interface are implicitly public abstract. However, when you implement them, you must explicitly specify the public.
{ expected Syntax: { expected after this token
  • Look for a missing { slightly before where it is complaining.
  • Usually it means you put a semicolon where one was not supposed to be ahead of a {, such as at the end of an implements or extends clause. There are many errors of this type the compiler cannot catch because Java slavishly copied C syntax. For example, getting your semicolons wrong in a for loop will generally not generate an error, just give surprising results.
} expected } expected. Type expected. Identifier expected.
  • Missing } at the end of a class.
  • Missing } is on a line containing // before the }.
  • Failure to enclose initialiser code in {} or static {}.
  • Code has to live inside some method, or inside some initialiser. It can’t just be left lying out in the middle of the class declarations.
  • forgetting static { } around class init code.
  • Perhaps 
    // Oops, interfaces extend other interfaces,
    // only classes can implement them.
    interface X implements Y
       {
       // ...
       }
    instead 
    // Correct. An interface extends another interface,
    // it cannot implement it.
    // A class extends another class or implements an interface.
    // An interface cannot extend or implement a class.
    interface X extends Y
       {
       // ...
       }

This page is posted
on the web at:

http://mindprod.com/jgloss/compileerrormessages.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\compileerrormessages.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.119.142.210]
You are visitor number