- cannot resolve symbol
- symbol : class someClass
The name of this class is not recognized. Check spelling and capitalization, and be sure you're using the full path name (eg.'cs015.Containers.Panel' instead of just 'Panel')
Incorrect number of parameters (caret points to the 'new', or to 'super' if called on a parent's constructor)
Actual parameters are of the wrong class. Careful on inheritance here (if you pass in a superclass when you asked for the subclass, for ex).
- symbol: variable some variable name
There is no reference to a variable of this name in the current scope. Make sure that you are using the correct variable name, and that you define and instantiate variables before using them.
- symbol: constructor some constructor class(parameters) (caret points to 'super')
The constructor that you are using is a valid class name, but the number and/or types of parameters do not match. Double-check that what you are passing in reflects what the class's constructor requires.
You may have forgotten to include a parameter list after a method call. To correct the problem, include a parameter list after the method name, even if that list is just ().
- No constructor matching someclass(someparameterlist) found in class someclass.
Although Java knows there is a class named someclass, it can't find a constructor with the same number and type of parameters you put in the list. Verify that your parameter list is correct and that you are calling a public constructor.
If Java reports the error on the first line of a constructor of a derived class, you may have forgotten to call the superclass constructor. Remember that if you do not include a call to the superclass constructor, Java will call super() automatically. However, if you have defined (a) constructor(s) in the superclass, and SuperClass() is not one of them, there is no method matching super(). In this case, provide a definition for SuperClass() or call a superclass constructor which is already defined.
- No method matching somemethod found in someclass.
Although Java knows there is a class named someclass, it can't find a method with the same number and type of parameters you put in the parameter list. Verify that the method you are calling exists in the public interface and that your parameter list is correct.
- Reference to variable somevariable in someclass as if it was a method.
You are adding parentheses to the end of the variable name. However, you really shouldn't be accessing variables via the . operator. Please see a TA to talk about why if you aren't sure.
- Superclass someclass of someotherclass not found.
You are trying to inherit from a class that does not exist, or you need to specify a more complete name for the superclass.
- Undefined variable or class name: somevariable
You are either trying to refer to a variable that Java doesn't know about or trying to access something in a package that Java can't find. Make sure that you are not trying to access a method as a variable(ie leaving off the "()") or you have spelled the package names correctly for all your references.
- Undefined variable or class name: somevariable
You are either trying to refer to a variable that Java doesn't know about or trying to access something in a package that Java can't find. Make sure that you are not trying to access a method as a variable(ie leaving off the "()") or you have spelled the package names correctly for all your references.
- Can't reference somevariable before the superclass constructor has been called
You are trying to refer to a variable declared in the superclass before calling the superclass constructor. Since the superclass constructor is responsible for properly initializing that variable, Java won't let you use a variable that may not have been properly initialized. To correct the problem, call the superclass constructor before using the variable, or declare the variable in subclass instead of superclass.
- symbol : class someClass
- class class is public, should be declared in a file named class.java
someinterface must be defined in a file called "somefile".You are trying to define or declare a public class or interface in a file which does not have the same name as the public class or interface (plus a .java extension). To correct the problem, declare the class or method non-public, or change the name of the file to match the name of the public class or interface. Note that you may define or declare at most one public class or interface per file.
- someclass is not abstract and does not override abstract method somemethod in someabstractclass
someclass extends someabstractclass but doesn't override somemethod. In order for a concrete class to extend an abstract class it must provide definitions for every abstract method in the abstract class. You must write a definition for somemethod in someclass.
- someclass is abstract; cannot be instantiated
You are trying to create an instance of an abstract superclass. To correct the problem, instantiate a subclass of <someclass>, or expand the definition of someclass so that it does not have to be abstract.
This error will appear if someclass is not defined abstract, but should be. That is, it frequently appears with the error "Class someclass must be declared abstract."
- someinterface is an interface. It cannot be instantiated.
You are trying to instantiate an interface. Since an interface cannot haveany definition, and is therefore abstract, this is impossible. To correct the problem, instantiate an implementation of <someinterface> instead.
- interface expected here
You are trying to implement a class instead of an interface. To correct the problem, extend the class rather than implement it, or declare someclass to be an interface instead of a class.
- someclass should be declared abstract; it does not define somemethod in someotherclass or someinterface.
You are trying to define a non-abstract class (that is, a class that you can instantiate) without implementing every method declared to be part of the public interface. Either write a definition for the method or declare the class as abstract.
- unclosed string literal
You have forgotten to close a constant string with a double quote.
- ')' expected.
You have forgotten a close parenthesis, or have declared an invalid parameter list. For example, you may need to pass a string to a method, but have forgotten to put " " around the text.
- '(' expected.
You may be trying to new an object without including a parameter list. Remember that you must always include a parameter list for every method call, including constructors, even if that list is simply ().
- '{' expected.
You have specified additional information on a line of code, whereas Java expected that you would begin a new block of code with a "{". For example, you may have put parantheses after a class name. Only method names, not class names, are followed by parantheses. In most cases, to correct the problem, delete the extraneous information and insert the bracket.
- '}' expected.
You may have forgotten to end the declaration of a class, interface, method, or block of code. Remember the following constructs end with "}" and begin with "{":
- All definitions
- Class
- Interface
- Method
- All code blocks
- if
- else
- try
- catch
- for
- etc.
Try deleting and retyping all of your "}" characters and watch Emacs correspond "}"s with "{".
Another possibility is that you did not want to end the block of code there, but you have done something on the next line of code that makes the compiler think the block of code should end. For example, if you use a visibility modifier (such as private) on a local variable, the compiler assumes this is meant to be an instance variable and the method you are in is over. In this case, the error message is followed by several others.
- All definitions
- possible loss of precision, found: double, required: int
You're trying to make a double equal to an int, or some related mismatching of Java base types (float, double, int). This can happen when you actually WANT to convert between base types, in which case you should explicitly cast (i.e.
double i; num = (int) i;). However, this error can also come up if you've accidentally mis-typed a variable, so be sure to make sure you actually want to cast the variable. - 'while' expected.
You are trying to use the keyword "do" outside of the construct of a loop. Since "do" is reserved by Java, this is not permitted. To correct the problem, use an identifier different than "do".
- 'break' outside switch or loop.
The keyword "break" only has semantic meaning inside a for, while, or do while loop or a switch statement. You may have accidently closed your loop or switch statement with a misplaced "}". Delete and retype all of your "}" characters and watch Emacs correspond "}"s with "{"s.
- orphaned case.
The keyword "case" only has semantic meaning inside a switch statement. You may have accidently closed your switch statement with a misplaced "}". Delete and retype all of your "}" characters and watch Emacs correspond "}"s with "{"s.
- exception exception has already been caught
You are trying to catch an exception that may have been thrown inside atry block of code, but that exception has already been caught by an earliercatch block. For example, the following code can produce the error:
try {
// do something
}
catch (RuntimeException e){
// do something else
}
catch (NullPointerException e){
// go crazy!
}
Since NullPointerException is a subclass of RuntimeException, if the try block throws a NullPointerException it will be caught by the first catch block. You cannot rethrow the exception and have it caught by the second catch block as well. To correct the problem, reorder the catch blocks so that Java attempts to catch subclass exceptions before superclass exceptions.
- 'catch' without 'try'.
The keyword "catch" only has semantic meaning immediately after a "try" block. To correct the problem, put the code preceding the "catch" statement in a "try" block.
- 'class' or 'interface' expected.
You have begun a class or interface definition or declaration with valid class or interface modifiers, but have not used the keyword "class" or "interface" immediately after the space separated list of modifiers, or have misspelled it. To correct the problem, insert the proper keyword, or correct the spelling error.
- 'continue' outside of loop.
The keyword "case" only has semantic meaning inside a for, while, or do while loop. You may have accidently closed your loop with a misplaced "}". Delete and retype all of your "}" characters and watch Emacs correspond "}"s with "{"s.
- orphaned 'default'
The keyword "default" only has semantic meaning inside a switch statement. You may have accidently closed your switch statement with a misplaced "}". Delete and retype all of your "}" characters and watch Emacs correspond "}"s with "{"s.
- 'else' without 'if'.
The keyword "else" only has semantic meaning inside an if statement. You may have accidently closed your switch statement with a misplaced "}". Delete and retype all of your "}" characters and watch Emacs correspond "}"s with "{"s.
- 'finally' without 'try'.
The keyword "finally" only has semantic meaning immediately after a "try" block. To correct the problem, put the code preceding the "finally" statement in a "try" block.
- cannot return a value from method whose result type is void.
somemethod has been declared to have a return type of "void", but you are trying to return some value from the method. To correct the problem, change the return type of the method, or call "return;" instead of "return value;".
Or, you are trying to return a value from a constructor. Same solution to problem.
- missing return value
somemethod has been declared to have a return type other than "void", but you are trying to return from the method without returning a value. To correct the problem, change the return type of the method, or call "return value;" instead of "return;".
- somefield; has private access in someclass
This error occurs when you try to access a private inst. var. of another class. You cannot access a variable (also called fields) of a class in another class if that variable is not either public, or protected if the other class is a subclass of the first. In general you should not be accessing variables directly, but rather using accessor methods. If you do not see why, speak to a TA about it.
- somevariable has private access in package.class
You may have declared a variable private in superclass, but tried to access it in subclass. Remember that private variables are visible only to instances of the class which contains them. Delete the reference to the private variable or change the visibility of the variable to protected (recommended), public, or package friendly (no visibility modifier).
- 'try' without 'catch' or 'finally'.
A "try" block allows you to attempt to execute code that may throw an exception which is not a RuntimeException. You must provide a way for Java to handle any possible exception that might be thrown by the code in the "try" block. To correct the problem, provide a "catch" block for each possible exception, or a "catch" block for none or some of the possible exceptions and a "finally" block.
- Abstract methods can't have a body
You have declared a method either abstract or native, but are trying to provide a definition for it as well. To correct the problem, delete the definition of the method and replace it with a semicolon, or declare the method to be both non-abstract and non-native.
- Array required, but somePackage.someclass found
Square brackets are used to access elements of an array. You cannot overload operators in Java, so this is the only use of the square brackets.
- Call to super must be first statement in constructor.
You are trying to call a superclass constructor within a subclass method which is not a constructor. You may be trying to call a superclass method instead, in which case you have forgotten the dot and the method name after super. To correct the problem, call a different superclass method, or delete the line.
- Cannot access someClass
bad class file: ./someClass.class
class file contains wrong class: someDirectory.someClass
Please remove or make sure it appears in the correct subdirectory of the classpath.This error will occur if you leave the package name out of the top line of the .java file
- Can't assign a value to a final variable somevariable
somevariable has been declared final, which means you cannot change its value after declaration. If you need to change the value of the variable, remove the final declaration from the variable declaration. If you need to give the variable an initial value, you can do so at the time of declaration.
- Can't assign a value tgo final variable somevariable.
Once a final variable has been assigned a value it cannot be changed. This includes a final value that has not been explicitly assigned a value by you the programmer, because Java will implicitly assign a new object the value 'null' or no object. To correct the problem either remove the final keyword, assign a value to the final variable at its declaration, or assign the final variable a value in every constructor you declare.
- somebasetype cannont be dereferenced.
You may be trying to call a method on a base type, such as an integer or boolean. Base types are not true objects, and therefore do not have any methods associated with them. To correct the problem, remove the method call, or use an object equivalent of a base type, such as an "Integer" instead of an "int".
- non-static method somemethod cannot be referenced from a static context
You are trying to call a non-static method statically. That is, you are specifying ClassName.MethodName(parameter list) rather than InstanceName.MethodName(parameter list). Only static methods can be executed by specifying the class name; all other methods require that you first make an instance of the class before calling the method. To correct the problem, declare the method to be static, or instantiate the class and call the method on the instance.
- ']' expected
You are creating an array incorrectly. You may be trying to specify the array dimension in the declaration. For instance, you cannot say:
String[10] myErrors;You need to specify the size when you actually create the array. For example, a proper array declaration is:
String[] myErrors = new String[10] - Can't subclass interfaces: someinterface
You are trying to extend an interface by creating a class. A class can only implement interfaces, not extend them. Correspondingly, an interface can only extend other interfaces, not implement them. To correct the problem, make the derived class an interface, or implement the interface instead of extending it.
- Class someclass already defined in somepackage or somefile.
You are trying to provide two different definitions for the same class within the same package. Class names must be unique on a package level. To correct this problem, change the name of the class for one definition, or delete the extra definition.
This error can also occur if you specifically tell the compiler to compile a file more than once during the same compile - Class someclass not found in new.
You are trying to create an instance of a class that Java doesn't know about. Check declaration spelling or try fully qualified name. You may also have completely forgotten to declare the class.
You may also have declared a method to accept a parameter type which Java does not know about. In this case, the error message will appear when you attempt to invoke the method and pass a parameter which does not correspond in type to the type declared in the method signature. Check the spelling of the parameter type or try the fully qualified name.
- Class someclass not found in type declaration.
You are trying to declare an instance of a class that Java doesn't know about. Check declaration spelling or try full path name. The class also may not have compiled completely or, if it is in another package, not been declared public.
You may also have forgotten to declare a file to be in a package, or have specified the incorrect package. Check the first Java code line of the file and ensure that it is a package statement and that the specified package is correct.
- Class someclass not found in =.
You are trying to assign a variable which is an instance of someclass to another variable, but Java doesn't know about someclass and therefore cannot properly perform the assignment. Check the spelling of the variable declaration or try the full path name.
- Class someclass not found in someotherclass.
You are trying to call a method on an instance of a class that Java doesn't know about. Check declaration spelling or try full path name
- Class or interface declaration expected.
You have included code in a .java file which is not part of a class or interface declaration or definition, or the first "package" line. You may have accidently closed a class or interface declaration or definition prematurely with a misplaced "}". Delete and retype all of your "}" characters and watch Emacs correspond "}"s with "{"s.
- Constructor invocation must be the first thing in a method.
You are trying to call a superclass constructor on a line other than the first line of a subclass constructor. To correct the problem, delete the superclass constructor call and let Java call super() automatically (note that this will only work if super() is defined, or there is no superclass constructor defined, in which case super() has been defined automatically by Java), or move the superclass constructor call to the first line of the subclass constructor.
- Duplicate variable declaration: somevariable was somevariable
You are trying to declare more than one variable with the same name, but possibly of a different type. Instance variable names must be unique within a class definition and local variable names must be unique within a method. To correct the problem, rename one of the variables, or delete one of the declarations.
- File somefile does not contain someclass as expected, but someotherclass. Please remove the file.
This error can occur for two reasons. The first is that somefile has been corrupted, and must be recreated. In this case, go to a shell and type:
rm somefileand respond with a 'y' when you are asked (y/n). Then try to compile your program again. The error should no longer appear; however, you may notice the error "Class someclass not found in type declaration." If this happens, you have probably forgotten to declare that the file in which someclass is defined is in the same package as the file in which the error occurs. Check to make sure that each file has a package line, that the package name is the same, and that both files appear in a directory with the same name as the package name.
- Final variables must be initialized: somevariable
You have declared a variable to be final, but have not given it a default initial value. Since a final method can never be assigned a value after declaration, it is important to give it a value at that time, even if it is only 0 or null.
- Identifier expected.
You may be trying to define a method as an instance variable. Remember that method definitions and calls must always be followed by a parameter list, even if it's just (). You may also be trying to call a method on an instance, but have forgotten to specify the method name. That is, you have written someinstance.(someparameterlist); To correct the problem, specify the correct method name before the parameter list.
You may have also specified a variable type, but not an identifer which should be of that variable type. For example, you may have written:
public void Apply(double) { sayHi(); }instead ofpublic void Apply(double time) { sayHi(); } - Illegal start of expression.
For some reason, Java believes that you have invalid syntax. Commonly, this error occurs when you attempt to create a method within another method. Double check all your curly braces and your parentheses to make sure you aren't missing one.
- Illegal start of type.
You are trying to substitute some non-alphanumeric character for a variable type. For example, you may have begun a parameter list with two open parentheses. When Java found the second, it noticed that it could not possibly represent the start of a variable type and raised the error message. To correct the problem, delete the extraneous characters and replace them with a defined variable type. Remember that variable types (specifically class names) must always began with a letter, although numbers may appear as subsequent characters.
Places variable types are expected include:
- parameter lists ( eg: Method(Type name) ) constructor calls ( eg: new Type() )
- instance variable declarations (eg: private Type name)
- method return ( eg: public Type Method() )
- Incompatible type for if. Can't convert int to boolean.
Make sure you're using the equality operator (==) rather than the assignment operator (=).
- Incompatible type for if. Can't convert null to boolean.
Unlike C++, null has no integer or boolean equivalent. It therefore cannot be used as a value in a conditional clause. To correct the problem, specify a condition that evaluates to a boolean.
- Incompatible type for if. Can't convert .* to boolean.
You are trying to specify a conditional clause for an if statement, but have specified some clause that cannot evaluate to a boolean. Remember that in Java, boolean values can only be created using the conditional operators == (equal), != (not equal), ! (not), && (and), and || (or). Reconstruct your expression using these operators so that it evaluates to a boolean.
- Incompatible type for =. Can't convert somevariable to someothervariable.
You are trying to assign the value of one variable to the value of another variable, but the variables are of a different type. This is not a problem if the target variable is of a class type which is a superclass of the source variable. However, in this case, Java has determined that the variable types are completely unrelated.
You may also have forgotten to specify the "extends" part of a class declaration, and are assigning something that should be the subclass to something else that should be the superclass (but isn't, because you forgot the "extends").
If this error occurs with errors such as "Class someclass not found in type declaration." or "Class someclass not found in =." then it is probably a sign of a misspelling. Check the spelling of the class type of the variable declaration or try using the full path name.
- Incompatible type for declaration. Can't convert java.lang.String to char.
You are trying to declare a char variable with a String. This is probably because you have placed the initial value inside double quotation marks. To correct the problem, use single quotation marks instead.
- Incompatible type for declaration. Can't convert someclass to someotherclass.
You are trying to declare a variable and assign the value of another variable to it, but the variables are of a different type. This is not a problem if the target variable is of a class type which is a superclass of the source variable. However, in this case, Java has determined that the variable types are completely unrelated.
You may also have forgotten to specify the "extends" part of a class declaration, and are assigning something that should be the subclass to something else that should be the superclass (but isn't, because you forgot the "extends").
If this error occurs with errors such as "Class someclass not found in type declaration." or "Class someclass not found in =." then it is probably a sign of a misspelling. Check the spelling of the class type of the variable declaration or try using the full path name.
- Incompatible type for switch. Can't convert someclass or somebasetype to int.
You are trying to switch on a variable type that cannot be reduced to a simple ordinal. Valid switch variable types are limited to int and char (or exotic types which can reduce to ints, like bytes). To correct the problem, use a variable of one of these two types, or use multiple if statements instead of a switch statement.
- Incompatible type for case. Can't convert someclass or somebasetype to int.
You are trying to specify a case of a switch statement that cannot be reduced to a simple ordinal. Valid cases are limited to ints and chars (or exotic types which can reduce to ints, like bytes). To correct the problem, use a variable of one of these two types, or use multiple if statements instead of a switch statement.
- Incompatible type for =. Explicit cast needed to convert java.lang.String to char.
You are trying to assign a String value to a char variable. This is probably because you have specified the new value inside double quotation marks. To correct the problem, use single quotation marks instead.
- Incompatible type for =. Explicit cast needed to convert someclass to someotherclass.
You are trying to assign the value of one variable to the value of another variable, but the variables are of a different type. This is not a problem if the target variable is of a class type which is a superclass of the source variable. However, in this case, the reverse is true. You are trying to assign a superclass variable to a subclass variable.
If this is what you really want to do, then include the cast and Java will successfully compile the statement. However, you should not be casting variables, except in cases where you might normally use a template. For example, extending a generic collection so that when you get objects out of it they are of a more specific class than Object is a valid use of casting.
- Inconsistent member declaration. At most one of public, protected or private may be specified.
You are trying to specify a method or variable as being more than one of the access keywords. In all likelihood you are using the 'private protected' modifier which was legal in Java 1.0 but is not in Java 1.1 and beyond. Select another access specifier.
- Interface fields can't be private or protected: somevariable
You are trying to declare a private or protected variable in an interface. Any variable declared in an interface is implicitly public, static, and final, and must be given an initial default value. That is, any variable declared in an interface can only exist as a class constant, cannot be hidden, and cannot ever have its value changed. To correct the problem, declare the variable non-private and non-protected, or delete the declaration.
- Interface methods can't be native, static, synchronized, final, private, or protected : somemethod
You are trying to declare a method native, static, synchronized, final, private, or protected in an interface. Any method declared in an interface is implicitly public and abstract, and cannot be declared otherwise. To correct the problem, declare the method non-native, non- static, non-synchronized, non-final, non-private, and non-protected, or delete the declaration.
- Interfaces can't have constructors.
You are trying to provide a constructor for an interface. Since an interface can only have public static final class constants as its fields, it can never have any variables to initialize in a constructor. To correct the problem, remove the constructor declaration or definition, or make the interface an abstract class instead.
- Invalid array dimension.
You are trying to create an array with an invalid size. Common errors of this type include trying to make an array of a negative size or trying to make an array of a decimal(ie 3.5). Arrays must be declared with positive integers.
- Invalid cast from someclass or somebasetype to someotherclass or someotherbasetype.
You are trying to perform a cast which, based on the types of the variables involved, cannot possibly be valid. For example, you may be trying to cast a base type into an object instance, or trying to cast an object instance into a class which is not a subclass of it. To correct the problem, cast the object into one of its subclasses, or delete the cast statement. (Note that unlikeC++, there is no correspondence between booleans and integers. You cannot cast between them.)
- Invalid character constant.
A character is only capable of holding a single character in it. Make sure that you are not trying to assign a String to a character. If you need a variable that holds more than one character, use a String instead of a character.
- Invalid character in input.
You are trying to specify a char or String with an invalid character. This problem usually arises when you try to use the backslash character. The backslash (\) signifies to Java that you would like to include a special escape character for your char or into your string. However, if you specify \ by itself, Java becomes confused. If you would like to specify the backslash character, use \\.
Here is a table of all valid escape sequences:
\n newline (\u000a) \t tab (\u0009) \b backspace (\u0008) \r return (\u000d) \f form feed (\u000c) \\ backslash (\u005c) \' single quote (\u0027) \" double quote (\u0022) \ddd a char by octal value each d is one of 0-7 \unnnn a char by hex value each n is one of 0-9,a,b,c,d,e,f - Class someclass not found in type declaration.
You are trying to declare an instance of a class that Java doesn't know about. Check declaration spelling or try full path name. The class also may not have compiled completely or, if it is in another package, not been declared public.
You may also have forgotten to declare a file to be in a package, or have specified the incorrect package. Check the first Java code line of the file and ensure that it is a package statement and that the specified package is correct. - Invalid array dimension.
You are trying to create an array with an invalid size. Common errors of this type include trying to make an array of a negative size or trying to make an array of a decimal(ie 3.5). Arrays must be declared with positive integers.
- Invalid expression statement.
You have written a statement that simply makes no sense in Java. For example, you are trying to execute a command that does not exist, or you are using an operator incorrectly, or you are evaluating an expression but not using its value for anything. This error can also occur if you try to invoke a method on an instance, but forget the parameter list. Remember that all method calls must include a parameter list, even if it is just ().
- Invalid left hand side of assignment.
You may be missing a semicolon at the end of an assignment statement.
- Invalid method declaration; return type required.
You are trying to declare a method without a return type. All methods except constructors must declare a return type. If you do not want to return a value from the method, specify the return type as void; otherwise, specify a valid class name or a base type.
for example:void Activate() { ... }
instead of:Activate() { ... }
If you are trying to write a constructor for a class, verify that the name of the constructor and the name of the class correspond.
You may also have written a Java statement outside the context of a method. Remember that all statements except declarations must appear inside methods which in turn appear inside classes. - Invalid type expression.
You may have forgotten to end the statement on the previous line with a semicolon.
- Method somemethod not found in someclass.
Although Java knows there is a class named someclass, it can't find a method with the same number and type of parameters you put in the parameter list. Verify that the method you are calling exists in the public interface and that your parameter list is correct.
- Method redefined with different return type: somereturntype somemethod was someotherreturntype somemethod
You are trying to redefine a method in a subclass, but have changed what type of value that method will return. Since an object which has a reference of superclass type expects the return value specified in the public interface of the superclass, any other return type is not permitted. To correct the error, adjust the return values of the method declarations so that they correspond.
- Methods can't be redefined with a different return type:
somereturntype somemethod was someotherreturntype somemethodYou are trying to overload a method solely on the basis of its return type. This can be problematic since assignment of the return type to a variable possibly could not provide enough information to determine which method to call. For example, the following creates an ambiguity:
class AClass {
// definition here
}
class ASubClass extends AClass {
// definition here
}
class ASecondClass {
public AClass DoSomething();
public ASubClass DoSomething();
}
class AThirdClass {
public void DoSomething() {
AClass anObject;
ASecondClass aSecondObject = new ASecondClass();
anObject = aSecondObject.DoSomething();
}
}
Since anObject can accept a variable of type AClass or of type ASubClass, Java cannot determine which method to call. To correct the problem, overload the methods on something other than return type, or delete the overloaded definitions until all methods with the same name have different parameter lists. - Missing method body, or declare abstract
You need to either define the method or declare the class as abstract.
- Missing Return Statement.
You have declared that a method will return a value (that is, you have declared its return type non-void), but have not ended the definition of the method with a return value; statement. To correct the problem, return a value, or change the return type of the method to void.
- Missing term.
You have forgotten one or more terms of an operator. For example, you may have specified the left side of a minus operator, but not the right. To correct the problem, specify the missing term.
- No variable somevariable defined in class someclass.
You are trying to directly access an instance variable of an instance or a static variable of a class which was never defined for that class, or for instances of that class. You may have misspelled the variable name, or simply forgotten the declaration. (But you shouldn't be accessing variables in other classes directly, anyways! Use accessor methods!
- Not a statement
_array[i][j] == null;Double equals sign can test for equality, but they need to be used w/in an if statement. A single equals sign should be used to assign value.
- Reference to somemethod is ambiguous. It is defined in somereturntype somemethodsomeparameterlist and %s.
You are trying to call an overloaded method, but are not passing in specific enough variable types to make method resolution possible. That is, given the variable types you are passing in, more than one version of the overloaded method could be called. Since Java does not know which one you intended to call, it cannot compile the line of code.
Java proceeds through a three-step "most-specific" process when it tries to match method name and parameter list to an actual function definition*:- Find all the methods that could possibly apply to the invocation, namely all the overloaded methods that have the correct name, and whose parameters are of types that can be assigned the values of all the arguments. If one method matches exactly for all arguments, you invoke that method.
- If any method in the set has parameter types that are all assignable to any other method in the set, the other method is removed from the set because it is less specific. Repeat until no eliminations can be made.
- If you are left with one method, that method is the most specific and will be the one invoked. If you have more than one method left, then the call is ambiguous, there being no most specific method, and the invoking code is invalid.
In this case, Java found more than one method with the correct function name and parameter list, but could not eliminate methods until only one remained using the process in step 2. To correct the problem, try defining a more specific version of the overloaded method to handle your particular case, or use variable types which will not produce an ambiguity.
*Taken from The Java Programming Language, by Ken Arnold and James Gosling, p. 109. - Reference to method somemethod in someclass as if it were a variable.
You are trying to access a method, but you are not putting parentheses at the end of the method name. For instance, if you were trying to access the method move in the instance _car, you would type:
_car.move();
not_car.move; - Too many errors. (The limit on reported errors is somenumber.)
If the compiler encounters too many errors in a row, it will not be able to proceed further with the compilation. If you see this, do not panic. Proceed by examining the first error, listed and fixing errors one at a time. Often one misplaced or missing, semicolon, brace or parenthesis, can throw off the entire compilation. Finding the first couple of errors can often therefore get rid of many of the others. If you cannot find the source of an error please see a TA.
- Unreachable statement
You have written a Java statement which cannot possibly be executed. For example, you have unconditionally returned from a function, but provided additional code to be executed after the return statement. Or, you may have placed code inside an if statement with a condition that will always be false. Java may also have noticed that the code preceding the statement will always fall into an infinite loop or recursion.
This error will also appear if you try to use more than 63 local variables in a method. - non-static variable this connot be referenced from a static context
You are trying to use this in a static method. Since static methods exist on a class, rather than an instance, level, but this always refers to an instance, this is not permitted. To correct the problem, eliminate the reference to this, or declare the method non-static.
- Variable somevariable might not have been initialized.
You are trying to use the value of a variable before assigning a value to that variable. To correct the problem, assign the variable a constant value or the return value of a function.
It is also possible that you have actually assigned the variable a value, but only inside the body of an if statement or other conditional statement. Java is then uncertain if it has received a valid value or not. To correct thisproblem assign the variable an explicit default value even if it is 0 or null.
another possibility - if you pass a variable into its own constructor, such as:
NGP.Containers.DrawingPanel dp = new NGP.Containers.DrawingPanel( dp ); - Variable 'somevariable' is already defined in method.
You are trying to declare a local variable with the same name as another local variable or a formal parameter. To correct the error, make the variable name unique.
- Modifier abstract, native, synchronized not allowed here
You are trying to declare a variable synchronized, abstract, or native. None of these modifiers is permitted for a variable. If you need the functionality that a synchronized variable would have provided, use the synchronized keyword inside a method definition. For example,
class AClass {
private int _variable;// how I wish this were synchronized
void DoSomething(){
synchronized(_variable){
// Now _variable acts like its synchronized
}
// Now it doesn't
}
}
To correct the problem, declare the variable non-synchronized, non-abstract, and non-native.
Is your error missing? Send mail to cs015tas@cs.brown.edu
