#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Java Class wasn't found in project error (using NetBeans)


    I am using NetBeans and doing my first graphics applet for a intro to Java class. I an getting a error "happyface.HappyFace class wasn't found in HappyFace project". The error brings up a box to chose a main class but in the box the only option is <no main classes found>.

    Here are my steps;

    1) create the project by selecting
    a) file
    b) new project
    c) category - java
    d) project - java application (other choices are java class library, java project with existing sources, java free form project)
    e) Next
    f) project name - "HappyFace" (create main class is selected and "happyface.HappyFace" in text box)
    2) I paste this exact code into the HappyFace.java file;

    import javax.swing.JApplet;
    import java.awt.Graphics;

    public class HappyFace extends JApplet
    {
    public void paint(Graphics canvas)
    {
    canvas.drawOval(100, 50, 200, 200);
    canvas.fillOval(155, 100, 10, 20);
    canvas.fillOval(230, 100, 10, 20);
    canvas.drawArc(150, 160, 100, 50, 180, 180);
    }
    }
    3) I build and clean successfully
    4) I run and get error above

    Also, the first line ("import javax.swing.JApplet;") shows an "incorrect package" error with choices to solve as "move class to correct folder" or "change package declaration to "HappyFace". I have chosen both options and neither solve the above issue.

    Note - I am clearly new to Java as this issue shows. I just installed JDK and netbeans and have successfully ran the usual "hello world" program.

    Any ideas or links to solution would be appreciated. thanks for your time.

    Ian
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by igilbert
    I am using NetBeans and doing my first graphics applet for a intro to Java class. I an getting a error "happyface.HappyFace class wasn't found in HappyFace project". The error brings up a box to chose a main class but in the box the only option is <no main classes found>.

    Here are my steps;

    1) create the project by selecting
    a) file
    b) new project
    c) category - java
    d) project - java application (other choices are java class library, java project with existing sources, java free form project)
    e) Next
    f) project name - "HappyFace" (create main class is selected and "happyface.HappyFace" in text box)
    2) I paste this exact code into the HappyFace.java file;

    import javax.swing.JApplet;
    import java.awt.Graphics;

    public class HappyFace extends JApplet
    {
    public void paint(Graphics canvas)
    {
    canvas.drawOval(100, 50, 200, 200);
    canvas.fillOval(155, 100, 10, 20);
    canvas.fillOval(230, 100, 10, 20);
    canvas.drawArc(150, 160, 100, 50, 180, 180);
    }
    }
    3) I build and clean successfully
    4) I run and get error above

    Also, the first line ("import javax.swing.JApplet;") shows an "incorrect package" error with choices to solve as "move class to correct folder" or "change package declaration to "HappyFace". I have chosen both options and neither solve the above issue.

    Note - I am clearly new to Java as this issue shows. I just installed JDK and netbeans and have successfully ran the usual "hello world" program.

    Any ideas or links to solution would be appreciated. thanks for your time.

    Ian
    OK - so I needed to chose "run file" instead of "run project". I am leaving the thread in case anyone else has this issue.

IMN logo majestic logo threadwatch logo seochat tools logo