Results 1 to 8 of 8
  1. #1
    ruchir123 is offline Member
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default Compilation Error in basic java class

    Hello,

    I am newbie. And, I have developed following java classes. But the child class is results in error. Below is step by step event. What am I doing wrong?

    Step 1. Created a compiled class Shirt(parent). No issues
    Java Code:
    public class Shirt {
    
     public int shirtID =0;
     public String description = "description required";
    // color codes
     public char colorCode = 'U';
     public double price = 0.0;
     public int quantityInStock = 0;
    
    // methods
    
    public void displayShirtInformation() {
       System.out.println("Shirt ID: " + shirtID);
       System.out.println("Shirt description:" + description);
       System.out.println("Color Code:" + colorCode);
       System.out.println("Shirt price: " + price);
       System.out.println("Quantity in Stock :" + quantityInStock);
     } // end of method
    } // end of class
    Step 2. Child class results in compilation error

    Java Code:
    public class ShirtTest{
    
     public static void main (Strings args[]) {
         Shirt myShirt;
         myShirt = new Shirt();
         myShirt.displayShirtInformation();
    
    }
    }
    Step 3. Error show below

    Java Code:
    C:\Java>javac ShirtTest.java
    ShirtTest.java:3: cannot find symbol
    symbol  : class Strings
    location: class ShirtTest
     public static void main (Strings args[]) {
                              ^
    ShirtTest.java:4: cannot find symbol
    symbol  : class Shirt
    location: class ShirtTest
         Shirt myShirt;
         ^
    ShirtTest.java:5: cannot find symbol
    symbol  : class Shirt
    location: class ShirtTest
         myShirt = new Shirt();
                       ^
    3 errors
    Thanks D,

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    About this,

    Java Code:
    public static void main (Strings args[]) {

  4. #4
    ruchir123 is offline Member
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default Error

    Thank you I have corrected as per your advice. Now the code looks like below

    Java Code:
    public class ShirtTest{
    
     public static void main (String args[]) {
         Shirt myShirt;
         myShirt = new Shirt();
         myShirt.displayShirtInformation();
    
    }
    }
    At the time of compilng above class, I still get following ERROR. :(
    Java Code:
    C:\Ruchir\Java>javac ShirtTest.java
    ShirtTest.java:4: cannot find symbol
    symbol  : class shirt
    location: class ShirtTest
         shirt myShirt;
         ^
    ShirtTest.java:5: cannot find symbol
    symbol  : class shirt
    location: class ShirtTest
         myShirt = new shirt();
                       ^
    2 errors
    Thanks,
    D

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  6. #6
    ruchir123 is offline Member
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default Error

    Oh yes. I have the parent class with same namin conventions. I mean, I now have Shirt class as 'S' capital. But still I am getting following error.

    Java Code:
    C:\Java>javac ShirtTest.java
    ShirtTest.java:4: cannot find symbol
    symbol  : class Shirt
    location: class ShirtTest
         Shirt myShirt;
         ^
    ShirtTest.java:5: cannot find symbol
    symbol  : class Shirt
    location: class ShirtTest
         myShirt = new Shirt();
                       ^
    2 errors
    And the actual code object is :
    Java Code:
    public class ShirtTest{
    
     public static void main (String args[]) {
         Shirt myShirt;
         myShirt = new Shirt();
         myShirt.displayShirtInformation();
    
    }
    }
    The parent Shirt class:
    Java Code:
    public class Shirt {
    
     public int shirtID =0;
     public String description = "description required";
    // color codes
     public char colorCode = 'U';
     public double price = 0.0;
     public int quantityInStock = 0;
    
    // methods
    
    public void displayShirtInformation() {
       System.out.println("Shirt ID: " + shirtID);
       System.out.println("Shirt description:" + description);
       System.out.println("Color Code:" + colorCode);
       System.out.println("Shirt price: " + price);
       System.out.println("Quantity in Stock :" + quantityInStock);
     } // end of method
    } // end of class

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  8. #8
    ruchir123 is offline Member
    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    Default

    That is correct. I have compiled the Shirt class and it has generated the .CLASS file. And Shirt and Shirtclass are located under same folder.

Similar Threads

  1. Replies: 2
    Last Post: 11-06-2011, 04:40 PM
  2. Basic Java applet error, cant figure it out!
    By alacn in forum Java Applets
    Replies: 3
    Last Post: 08-03-2010, 06:25 PM
  3. bean compilation error
    By technical_helps@yahoo.com in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 07-29-2009, 11:21 PM
  4. java.lang.Error: Unresolved compilation problems
    By jon80 in forum New To Java
    Replies: 0
    Last Post: 06-07-2009, 10:04 PM
  5. JAVA compilation error in UNIX
    By satish kumar in forum Advanced Java
    Replies: 9
    Last Post: 08-08-2008, 07:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •