newbie Java question: 2 files in one project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Johann Fu
    New Member
    • Oct 2011
    • 1

    newbie Java question: 2 files in one project

    I am learning Java. I am using NetBeans. I created a new project named TestCircle using the default package name provided by NetBeans, which is the same as the file name but all in lower case. The file is TestCircle.java :

    Code:
    // TestCircle.java
    package testcircle;
    public class TestCircle {
        public static void main(String[] args) {        
            //Circle myCircle = new Circle();
        }
    }
    Then I right-clicked the project name and added a new class file named Circle:
    Code:
    // Circle.java
    public class Circle {   
        int radius;   
        // constructor
        Circle(){
        }
    }
    I right-click the project and do a Clean and Build. There are no errors.


    But when I un-comment the line:
    Code:
    //Circle myCircle = new Circle();
    I get a compile error. Here is part of the compile output:
    Code:
    Compiling 2 source files to C:\Users\JohannFu\Documents\NetBeansProjects\TestCircle\build\classes
    C:\Users\JohannFu\Documents\NetBeansProjects\TestCircle\src\testcircle\TestCircle.java:6: cannot find symbol
    symbol  : class Circle
    location: class testcircle.TestCircle
            Circle myCircle = new Circle();
    C:\Users\JohannFu\Documents\NetBeansProjects\TestCircle\src\testcircle\TestCircle.java:6: cannot find symbol
    symbol  : class Circle
    location: class testcircle.TestCircle
            Circle myCircle = new Circle();
    2 errors
    So it looks like as soon as I try to instantiate a Circle object, the TestCircle class cannot find the Circle class!
    What am I doing wrong? Thanks for any help!
    Last edited by Frinavale; Oct 7 '11, 07:45 PM. Reason: Added code tags. Please post code in code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You need to include a reference to your first Circle class into your TestCircle class in order to be able to use it in your TestCircle class.

    Or maybe put them in the same namespace...not sure how this works in Java though...

    Aha a Java Package

    I think that if you import Circle into TestClass you should be golden.

    -Frinny
    Last edited by Frinavale; Oct 7 '11, 07:49 PM.

    Comment

    Working...