Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: cannot find symbol

  1. #1
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    124
    Rep Power
    0

    Default cannot find symbol

    So im following a tutorial that teaches java swing, but there is no words about compiling the thing. So im getting an error : Donut.java:11: cannot find symbol symbol : class Board location : class donut.Donut add(new Board());

    Code itself is in 2 class files.
    Java Code:
    package donut;
    
    import java.awt.BasicStroke;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.Ellipse2D;
    
    import javax.swing.JPanel;
    
    
    public class Board extends JPanel{
    
        public void paint(Graphics g)
        {
          super.paint(g);
    
          Graphics2D g2 = (Graphics2D) g;
    
          RenderingHints rh =
                new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                                   RenderingHints.VALUE_ANTIALIAS_ON);
    
          rh.put(RenderingHints.KEY_RENDERING,
                 RenderingHints.VALUE_RENDER_QUALITY);
    
          g2.setRenderingHints(rh);
    
          Dimension size = getSize();
          double w = size.getWidth();
          double h = size.getHeight();
    
          Ellipse2D e = new Ellipse2D.Double(0, 0, 80, 130);
          g2.setStroke(new BasicStroke(1));
          g2.setColor(Color.gray);
    
    
          for (double deg = 0; deg < 360; deg += 5) {
              AffineTransform at =
                  AffineTransform.getTranslateInstance(w / 2, h / 2);
              at.rotate(Math.toRadians(deg));
              g2.draw(at.createTransformedShape(e));
            }
        }
    }
    and

    Java Code:
    package donut;
    
    import javax.swing.JFrame;
    
    
    public class Donut extends JFrame {
    
    
        public Donut() {
    
            add(new Board());
    
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(360, 310);
            setLocationRelativeTo(null);
            setTitle("Donut");
            setVisible(true);
        }
    
        public static void main(String[] args) {
            new Donut();
        }
    }
    How to fix this problem

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,013
    Rep Power
    10

    Default Re: cannot find symbol

    How is your directory structure set up? How are you compiling this?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    124
    Rep Power
    0

    Default Re: cannot find symbol

    They both are at the same folder. and im using the javac command in cmd to compile it. javac *.java.

    and im also getting could not find or load main class Donut.class

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: cannot find symbol

    Moved from a staff-only section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: cannot find symbol

    Quote Originally Posted by vastrolorde View Post
    So im following a tutorial that teaches java swing, but there is no words about compiling the thing.
    Swing isn't a starting point for learning Java. Start here: The Java™ Tutorials

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    124
    Rep Power
    0

    Default Re: cannot find symbol

    Main problem i have with java is the compiling side. I have studied c++ for a few years, so i get the basics of java, few commands here and there and a different outlook but inside its similar. Compiler for c++ are so much more user friendly than the java compiler. I had a lot of trouble to get the javac even working. So my guess is that i either have something somewhere wrong or the 2 files just dont see eachother.

  7. #7
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    124
    Rep Power
    0

    Default Re: cannot find symbol

    I used java bit wrong at first. after i used javac *.class it started working.

  8. #8
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,013
    Rep Power
    10

    Default Re: cannot find symbol

    Quote Originally Posted by vastrolorde View Post
    I used java bit wrong at first. after i used javac *.class it started working.
    That doesn't seem right. You should use javac to compile your .java files, which creates .class files. You then use the java command to run one of the .class files. I'd suggest copying and pasting exactly what you're doing from the command prompt, as it seems like you're doing something strange.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. #9
    Russd772 is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default Re: cannot find symbol

    are you using command prompt for a specific reason? i know some people prefer it but possibly a java IDE like Eclipse or netbeans might be helpfull in this situation? then your compile and run is just a click and you can spend more time focusing on learning java and less time on learning command propts. unless of course your using an OS that is command based

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,013
    Rep Power
    10

    Default Re: cannot find symbol

    Quote Originally Posted by Russd772 View Post
    are you using command prompt for a specific reason? i know some people prefer it but possibly a java IDE like Eclipse or netbeans might be helpfull in this situation? then your compile and run is just a click and you can spend more time focusing on learning java and less time on learning command propts. unless of course your using an OS that is command based
    I'm going to go ahead and disagree here. It is precisely due to misunderstanding the basics such as the difference between a .java file and a .class file that novices should stick with the command prompt, at least for the first few weeks. An IDE might hide that from you, but that doesn't make the problem go away.
    DarrylBurke likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    106
    Rep Power
    0

    Default Re: cannot find symbol

    I second the motion to use a decent IDE such as Eclipse. Using Eclipse, i got the code to work in short order. I do know how to use the command line. I had to use the command line for a whole Java course. I'm just glad that now I can use Eclipse.

    Eclipse Download:
    Eclipse IDE for Java Developers | Eclipse Packages

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: cannot find symbol

    Quote Originally Posted by kaydell2 View Post
    I do know how to use the command line.
    But vastrolorde doesn't. And that should come first.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Cannot find symbol
    By sam.jj12 in forum AWT / Swing
    Replies: 2
    Last Post: 09-16-2012, 02:27 PM
  2. Cannot find Symbol
    By webbby in forum New To Java
    Replies: 3
    Last Post: 04-14-2011, 01:51 AM
  3. Cannot find symbol
    By shane5317 in forum AWT / Swing
    Replies: 3
    Last Post: 03-02-2011, 12:36 PM
  4. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  5. Replies: 3
    Last Post: 05-01-2008, 09:30 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
  •