Sei sulla pagina 1di 30

compile time error messages : Java Glossary

Creative Writing Classes


www.FullSail.edu C reate C ompelling Stories and Bring them to the Screen. Full Sail Univ.

punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all)


home Java Glossary C words compile time error messages

You are here :

1996-2013 reviewed:2008-08-30 Roedy Green, Canadian Mind Products

compile time error messages This table contains errors detected at compile time. If you dont find your error listed here, send me an email at 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.

run time error messages error messages


Index To Compile Time Error Messages

( expected . expected .class expected ; expected ; missing


open in browser PRO version

class, enum or interface expected

not accessible not found in import not initialised operator + operator ||


pdfcrowd.com

classname not enclosing class Comparable cannot be inherited constructor calls overridden method constructor used as method
Are you a developer? Try out the HTML to PDF API

= expected [ expected already defined ambiguous class array not initialised attempt to reference attempt to rename bad class file blank final boolean dereferenced bound mismatch cannot find symbol cannot override, attempting weaker access cannot override, does not throw cannot override, incompatible return type

duplicate class duplicate methods


enum as identifier

package does not exist permission denied possible loss of precision


public class should be in file

error while writing Exception never thrown


final parameter may not be assigned

reached end of file recompile with -Xlint:unchecked redefined method reference ambiguous repeated modifier return in constructor return outside method return required serialVersionUID required should be declared in file statement expected static field should be accessed in a static way
static not valid on constructor

generic array creation identifier expected illegal character illegal escape illegal forward reference illegal reference to static illegal start impotent setters incompatible type

cannot resolve constructor cannot resolve symbol


open in browser PRO version

instance not accessible invalid declaration

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

cannot resolve symbol constructor Thread cannot resolve symbol this cannot use operator new cant access class cant be applied cant be dereferenced cant be instantiated; cant convert from Object to X cant delete jar file cant determine application home cant instantiate abstract class cant make static reference capitalisation errors case fallthru char cannot be dereferenced clashes with package
class expected

invalid flag invalid label invalid method invalid type javac is not a command main must be static void method cannot hide method clone not visible method matches constructor name method not found misplaced construct misplaced package missing init missing method body missing public missing return statement missing variable initialiser name of constructor mismatch no field

superclass not found suspicious shadowing Tag @see: not found type cant be private type cant be widened type expected type safety type safety: type erased unable to resolve class unchecked cast unchecked conversion unclosed character literal unclosed String literal undefined reference to main undefined variable unexpected symbols unqualified enumeration required unreachable statement unsorted switch
pdfcrowd.com

class has wrong version class must be defined in a file


open in browser PRO version

Are you a developer? Try out the HTML to PDF API

class names only accepted for annotation class not found class not found in import class not found in type declaration class or interface declaration expected class should be declared in file
Compiler Error Messages
reached end of file while parsing"

no method found no method matching non-final variable non-static cant be referenced not a statement not abstract

void type weaker access { expected } expected

Compiler Error Messages


Key Real Error / Possible Causes
( expected
( expected instead of {.

What Compiler Says

// 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. Usually pointing to an import statement.

. expected

You must import either a packagename.* or packagename. Classname. You cant just import packagename or import Classname. You dont import classes in the same package as the current class. In other words, the thing you import will always contain at least one .. You dont 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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 dont import classes without packages.

.class expected
you wrote int i where you meant just plain i.

'.class expected

; expected
Usually this is just a missing semicolon, sometimes it can be caused by unbalanced () on the previous line.

semicolon expected.

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. ';' expected. 'else' without if. statement expected. invalid expression.

; missing
missing semicolon. See ; expected .

= expected
Look for a stray } just before where it is complaining.

= expected.

[ expected
Likely you wrote [i,j] instead of [i][j].

Missing [

already defined
duplicate variable declaration

Variable 'x' is already defined in this method.

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;
open in browser PRO version
Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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.

import
array not initialised
You forgot to initialise an array with new int[5]. Array a may not have been initialized.

attempt to reference
missing dummy pair of parentheses after the 0-argument method name.

Attempt to reference method xxx in class XXX as an instance variable.

attempt to rename
Your jar is in use by some running Applet or application. Shut it down to build and sign the jar.

jarsigner: attempt to rename xxx.jar to xxx.jar.orig failed.

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.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Boolean dereferenced
You need extra layers of parentheses around your casting.

Boolean cannot be dereferenced.

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.

cant access class

Cant 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 C:\com\mindprod\thepackage

cant 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 aint what you dont know that gets you into trouble. Its what you know for sure that just aint so. ~ Mark Twain (born: 1835-11-30 died: 1910-04-21 at age: 74)

cant 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 cant have any instance methods. They can be parameters to either static or instance methods though. load: com.mindprod.mypackage.MyApplet.class cant be instantiated.

cant 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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

cant 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 navely expect. You tried to use a general Object reference in a context that requires something more specific. Sometimes all you need is a cast.

cant determine application home

Cant determine application home.

Uninstall all Java JDKs (Java Development Kits) and JREs (Java Runtime Environments) with the Control Panel. Use Microsofts 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 classs 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.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.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Using the -verbose option on javac.exe will give you hints to help resolve this error. Cannot Resolve Symbol

cant instantiate abstract class


missing method to fulfill an interface implementation

Error: MyClass is an abstract class. It cant be instantiated.

cant make static reference


using an instance variable in a static method

Cant make a static reference to nonstatic variable x in MyClass.

cannot override
You can override a default or protected method with a public one, but not the reverse.

toString() in xxx cannot override toString() in java.lang.Object; attempting to assign weaker access privileges; was public.

cannot override
Overridden methods cannot add any throws clauses not in the base method they are overriding.

toString() in xxx cannot override toString() in java.lang.Object; overridden method does not throw java.io.IOException

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


No such variable or method. Perhaps it exists, but not in the current scope that loop. You left off the () on your method call.

Cannot resolve symbol , e.g. you are trying to use a variable defined inside a loop outside

Possibly you are trying to use a constructor without new as if it were an ordinary method. 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.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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.

// Using subclass methods. // In this case, MultiFilter.addNever() is implemented // in MultiFilter but not in the base FileNameFilter. // oops. f. has no addNever method. FileNameFilter f = new MultiFilter(); f.addNever( never ); // should read FileNameFilter f = new MultiFilter(); ((MultiFilter)f).addNever( never ); // or more efficiently MultiFilter f = new MultiFilter(); f.addNever( never );
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
You forgot to write implements Runnable on the class with the run method. cannot resolve symbol constructor Thread( YourRunnable )

cannot resolve symbol this

Cannot resolve symbol this.xxx

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 cant 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.

cant delete jar file


You are running the application from the old jar. Shut it down before rebuilding.

Ant complains it cannot delete the jar file during a build

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 dont 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


class name does not match source filename. Putting more than one public class per file.

Warning: ublic MyClass must be defined in a file called 'MyClass.java'.

Getting the capitalisation wrong in the filename on the javac command line or in the filename itself. Error: Class names, 'XXX', are only accepted if annotation processing is explicitly requested

class names only accepted for annotation processing

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:

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

javac.exe MyClass.java
This is one of the most maliciously misleading of all error messages.

class not found


This can occur at compile or run time. You are using Internet Explorer which has a defective or missing Java.

Class not found

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 com.mindprod.mypackage.Myclass not found in an import

class not found in 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. importjava.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. Im 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.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You may have too many } so that you have finished off your class before you intended too. Using a source code beautifier block and {} will help make these sorts of errors obvious.

that aligns code

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 with different arguments

Comparable cannot be inherited

// base class class SalesTaxItem implements Comparable<SalesTaxItem> {


...

// subclass class DatedSalesTaxItem extends SalesTaxItem implements Comparable<DatedSalesTaxItem {


...

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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

duplicate class duplicate methods

Duplicate class

You misspelled the package name on the package statement. It must match the name of the directory containing the Java source. duplicate method declaration

You have two methods with the same name and the same signature i.e. number and types of parameters. You cant 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, Javas generics are Mickey Mouse. One of the side effects of the el-cheapo implementation is that you cant have arrays of generic collections, e. g. the following is illegal

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

// You cannot use "new" to allocate an array of T where T is a generic type, e.g. <T>. // Recall that even if it did, it would still allocate an array of Objects at run time. T[] things = new T[10]; // Illegal attempt to create an array of generic collections. ArrayList<String>[] stuff = new ArrayList<String>[ 10 ];
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.

literals
illegal forward reference
Probable forward enum reference

You may not reference an enum constant that has not yet been defined. I.e. you can reference other enum constants in an enum constructor call.

illegal reference to static

illegal reference to static field from initialiser

enum constructors cannot access the enum static fields. However, they can invoke the enums static methods that access the static fields, but they wont 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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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? Youd 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
The error message will point to perfectly good code. Look just ahead of it for a missing } 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. or ;

illegal start of expression

incompatible type
missing a cast such as (byte)

Incompatible type for =. Explicit cast needed to convert int to byte.

instance not accessible


Something is wrong with the parameters to an inner class.

Error: An instance of XXX.this is not accessible here because it would have to cross a static region in the intervening type XXX.

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.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

invalid label
You used a semicolon instead of a colon after a label.

invalid 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
You forgot the semicolon.

Invalid type expression.

javac is not a command

javac is not an internal or external command operable statement or batch file . See JDK for details on polishing and testing your

J:\Program Files\java\jdk1.7.0_25 \bin\javac.exe must be on the path JDK installation.


main must be static void

main must be static and void

An applications 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 cant 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. 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.

method matches constructor name


You cant put void on a constructor, or put any other return type for that matter.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

method not found


undefined (missing) method. You wrote MyClass x = MyClass(); instead of MyClass x = new MyClass();

Method MyClass() not found in 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. Error: com/sun/java/swing/xxx is either a misplaced package name or a non-existent entity.

misplaced package

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


You inserted a semicolon just before the first { of a method.

missing method body, or declare abstract

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 cant be so sure.

name of constructor mismatch


You forgot your return type, e.g. void, on a method.

The name of the constructor main does not match name of class MyClass

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 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.


Are you a developer? Try out the HTML to PDF API

open in browser PRO version

pdfcrowd.com

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
missing caps on a class name declaration. Caps on a variable/method declaration

no warning. caps missing.

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; }
no warning. missing public.

missing public

In debug mode, if you forget to make your main method public, you will not be warned. You wont discover the problem until later. main must be public static void.

case fallthru

no warning. Case fall through is the default. no warning. Missing initialisation.


Are you a developer? Try out the HTML to PDF API

missing break. In Java version 1.4 or later you can use the javac.exe -Xswitchcheck to get this error detected.

missing initialisation

open in browser PRO version

pdfcrowd.com

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


Dont put () around the dot-separated parts of a name.

missing variable initialiser

constructor treated as method


specifying a void return type on a constructor. Method with the same name as the class.

no warning. Constructor treated as a method. no warning. reusing instance variable as local.

suspicious shadowing

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.

JPCC
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 subclasss version, which may be attempting to use fields that have not been initialised yet. You wont 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. 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.

non-final variable

Inside anonymous classes, you cant use local variables of the enclosing method unless they are final. I dont mean instance or static variables. I dont 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 cant be referenced

non-static method xxx cannot be referenced from a static context

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 dont have access to any particular object, so cant 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 cant 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. xxx.this is not accessible here because it would have to cross a static region in the intervening type.

not accessible

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 cant create anonymous inner classes except inside instance methods.

not found in import

not found in import.


Are you a developer? Try out the HTML to PDF API

open in browser PRO version

pdfcrowd.com

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 . 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.

not initialised

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 +
Irritatingly, Java does not allow unary + in front of a String, only between Strings so you cant write

operator + cannot be applied java.lang.String

// oops, lead + not allowed even though it would be nice for alignment and consistency result = + "cow " + "rabbit " + "horse ";
operator ||
you wrote if ( x1 = x2 || y1 = y2 ) instead of if ( x1 == x2 || y1 == y2 ) operator || cannot be applied to int,int

package does not exist

Package Java.Applet[sic] does not exist.

Java is case sensitive. The package is called java.applet, not Java.Applet[sic]. 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 );
open in browser PRO version
Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You should use an import for the outer class. You dont need to import the inner, though you may optionally do so. Dont try to use * notation to import the inner class.. error while writing XXX: XXX.class (Permission denied)

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 dont 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 cant override it. Use some other name. The same applies to the automatically constructed methods, compareTo, ordinal, and equals.

Recompile with -Xlint:unchecked


You used a Collection without generifying

XXX uses unchecked or unsafe operations. Recompile with -Xlint:unchecked for details it. If it is not obvious what the problem is, recompile with javac.exe -Xlint:unchecked 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.

*.java

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

reference ambiguous

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
specifying a return this in a constructor

'return' with value from constructor: MyClass(..).

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
specifying a MyClass return type on a constructor

Return required at end of MyClass Myclass(..).

serialVersionUID required
Assign your class a serialVersionUID

serializable class XXX has no definition of

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 is not a valid constructor modifier

static not valid on constructor


You forgot your return type e.g. void, on a method.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 cant point to a class whose Javadoc is not in the bundle.

superclass not found


Did you remember to import the YYY class?

Superclass YYY of class XXX not found.

type cant be private


Top level classes cant be private, only classes nested inside others.

The type MyClass cant be private. Package members are always accessible within the current package.

type cannot be widened

the type of this expression, ' double', cannot be promoted to 'int' by widening conversion. for the code you need.

Java cannot automatically convert a double to an int. There are many options. See Converter Amanuensis

type expected

Type expected. identifier expected. , or literally a missing type, especially in constant declarations like: public static final SOMETHING=3; instead of public

extra }

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 cant 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 }. Eclipse error: Type safety: Unchecked invocation sort(List<X>) of the generic method sort(List<X>) of type Collections X .

type safety

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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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 cant tell if it truly is an ArrayList< String>. If it isnt, 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 runtime 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
You used a Collection without generifying

Warning: [unchecked] unchecked conversion it. If it is not obvious what the problem is, recompile with javac.exe -Xlint:unchecked unclosed character literal

*.java

unclosed character literal

Single char literals are enclosed in 's. Strings. 1-character Strings are enclosed in "s. You may have used ' around a String, or used an invalid representation for a char literal .

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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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
The code potentially throws an exception. You must either wrap it in a

java.text.ParseException; must be
caught or declared to be thrown.

try {} catch (ParseException e) {}


unsorted switch

or put a throws declaration on the method to let the caller deal with it. Unsorted lookup switch

Java wont 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
Look for a missing { slightly before where it is complaining.

Syntax: { expected after this token

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.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

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. at the end of a class.

Missing }

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 cant 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 { // ... }

balancing CheckStyle error messages run time error messages


open in browser PRO version
Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

available on the web at: optional Replicator mirror of mindprod.com on local hard disk J:

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

Please email your feedback for publication , letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : . If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I cant very well fix erroneous or ambiguous text if I cant find it.

Blog Feedback

Canadian Mind Products


You are visitor number

IP:[65.110.21.43] Your face IP:[69.164.218.62]

584,435.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Poorly secured nuclear material in the former Soviet Union, or secrets from a scientist in Pakistan could help build a bomb that detonates in Paris. The poppies in Afghanistan become the heroin in Berlin. The poverty and violence in Somalia breeds the terror of tomorrow. ~ Barack Obama (born: 1961-08-04 age: 52)

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Potrebbero piacerti anche