Sunday, November 30, 2008

Published 11/30/2008 by with 3 comments

class [ClassName] is public, should be declared in a file named [ClassName].java

We get error message "class [ClassName] is public, should be declared in a file named [ClassName].java" if the file name of the Java source program is not same as the public class name. Solution is to rename the file or the class name to make them same. If a public class name is ABC then the file name of that class must be ABC.java. So always copy the class name and paste it when naming the file,...
Read More
    email this       edit

Tuesday, November 18, 2008

Published 11/18/2008 by with 0 comment

Exception in thread "main" java.lang.NoSuchMethodError: main

'Exception in thread "main" java.lang.NoSuchMethodError: main' is a run time error message. If the main method is not properly defined, we may see this error message. You know if you want to execute/run a program that program must have a main method of the following signature: public static void main(String args[]) Generally we do the following mistakes in this regard: 1. May be, you haven't defined...
Read More
    email this       edit
Published 11/18/2008 by with 0 comment

is already defined

If we declare a variable in a method more than once than we see ' is already defined'. Find out the variable for which the message is shown and check whether you have declared the variable more than one time in a particular block. If we compile the following code we will see 'country is already defined in myMethod()' public class AlreadyDefinedSolution { public void myMethod() { String country; String...
Read More
    email this       edit
Published 11/18/2008 by with 1 comment

reached end of file while parsing

The error 'reached end of file while parsing' occurs because of curly braces } problem. You have given either more or less curly braces } than the required number of } braces. See the code below: public class ReachedEndOfFileWhileParsing { public static void main(String args[]) { System.out.println("java-error-massages.blogspot.com"); } Here two curly braces are started but only one is ended. We...
Read More
    email this       edit

Sunday, November 9, 2008

Published 11/09/2008 by with 2 comments

possible loss of precision

You may see the error message 'possible loss of precision' for any of the following reasons: 1) You are trying to assign a fractional number into a float variable(why not?). Actually Java compiler considers the fractional number as double by default. You need to explicitly specify the fractional number as float by giving the character 'f' or 'F' after the the number, like float number = 65.37F; 2)...
Read More
    email this       edit
Published 11/09/2008 by with 1 comment

integer number too large

We know that the maximum value of an int is 2147483647. If we write any whole number more than 2147483647 in our Java program, we may get this error message 'integer number too large' but may be you are trying to store this large number in a long type variable, then what to do? The solution is to put the letter 'l' or 'L' after the number. This happens, because the compiler considers the whole number...
Read More
    email this       edit

Tuesday, November 4, 2008

Published 11/04/2008 by with 0 comment

; (semi-colon) expected

Each java statement must ends with ; (semicolon) in Java. If we don’t put ; after any statement we will see ‘;’ expected Here is an example of this error: public class SemicolonExpected { public static void main(String args[]) { int x=10,y=10 //no ; (semicolon) is given after this statement if(x==y) System.out.println(x +" and "+y+" is equal"); } } Here no ; (semicolon) is given after the x,y...
Read More
    email this       edit
Published 11/04/2008 by with 0 comment

variable … might not have been initialized

We see “variable might not have been initialized” when we try to use the value of a variable before assigning any value to that variable. Each local variable must be assigned a value before further using it. Here is an example of this error : public class VariableMightNotHaveBeenInitialized { public static void main(String args[]) { int a,b,c; a=10; c=a+b; System.out.println("The sum is "+c); } } Here...
Read More
    email this       edit
Published 11/04/2008 by with 0 comment

missing method body, or declare abstract

If we put a ; (semicolon) after the method header (i.e., before starting the method body) when we are defining a concrete method (which method has body) then we will see “missing method body, or declare abstract”. Another reason is if we don’t write the keyword ‘abstract’ for an abstract method (a method without body), we’ll also see this message. To resolve the problem we must remove the ; (semicolon)...
Read More
    email this       edit
Published 11/04/2008 by with 0 comment

else without if

Programmers may see message “else without if” when the selection (if ... else if ... else) structure is used. This may happen for any of the following reasons: Semicolon (;) is given after the last parenthesis of the condition Error in use of the curly braces ( } ), may be the } is not closed before starting the next else if or the else or } is given more. Here is an example of this error: public...
Read More
    email this       edit
Published 11/04/2008 by with 0 comment

cannot find symbol / cannot resolve symbol

“cannot find symbol” or “cannot resolve symbol” is the most common error message which the programmers get from the compiler. However this error message may mean that the variable/method/class/object used are not declared/defined properly. In most cases, this happens because: · The variable/object is not declared or the spelling of variable/object declaration & later use of that variable/object...
Read More
    email this       edit