Friday, May 24, 2013

[Java][Resolved] unclosed character literal

Error message:
java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
    at javaapplication1.JavaApplication1.main(JavaApplication1.java:43)

A part of the Code:
public class JavaApplication1 {     
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try{
            Car car = new Car();
            car.defineColor('gray');
           
        }
        catch (Exception e){
            e.printStackTrace ();
        }       
        // TODO code application logic here
    }
   
}
How to fix the problem:
car.defineColor('gray');
car.defineColor("gray");
Code after edited:

public class JavaApplication1 {     
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try{
            Car car = new Car();
            car.defineColor("gray");
           
        }
        catch (Exception e){
            e.printStackTrace ();
        }       
        // TODO code application logic here
    }
   
}
Reason by Ravi Thapliyal :
Java uses double quotes for "String" and single quotes for 'C'haracters. So in my case, i should not use singe quotes for the String gray, i should use double quotes for it.


No comments :

Post a Comment