1,105,578 Community Members

Error "cannot find symbol constructor"

Member Avatar
zach&kody
Newbie Poster
17 posts since Feb 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

After compiling this code, I am getting a "cannot find symbol constructor Timer(int,Morning)" on line 17.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Morning extends JFrame
{
  private EasySound rooster;
  private int time;

  /**
   *   Constructor
   */

  public Morning (int time)
  {
  	time = 0;
  	Timer clock = new Timer(30, this);
  	clock.start();
  }
  
  public Morning()
  {
  	super("Morning");
    rooster = new EasySound("roost.wav");
    rooster.play();

    Container c = getContentPane();
    c.setBackground(Color.WHITE);
  }

  public static void main(String[] args)
  {
    Morning morning = new Morning();
    morning.setSize(300, 150);
    morning.setDefaultCloseOperation(EXIT_ON_CLOSE);
    morning.setVisible(true);
  }
}
Member Avatar
Taywin
Posting Maven
2,632 posts since Apr 2010
Reputation Points: 134 [?]
Q&As Helped to Solve: 378 [?]
Skill Endorsements: 17 [?]
 
1
 

Because the class "Timer" constructor prototype doesn't have the type you are declaring. Where is your Timer class? And what are its constructors?

// do you have this type of constructor in your Timer class?
public Timer(int anInt, Morning aMonringObj) {
 ...
}
Member Avatar
gusano79
Practically a Posting Shark
816 posts since May 2004
Reputation Points: 203 [?]
Q&As Helped to Solve: 131 [?]
Skill Endorsements: 10 [?]
 
0
 

The second parameter to the Timer constructor you're using needs to implement ActionListener . JFrame doesn't implement it, so you'll have to do that in your Morning class yourself.

Also: You'll get better results posting questions like this in the Java forum.

Member Avatar
zach&kody
Newbie Poster
17 posts since Feb 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

The problem is, I don't know what to put in place of super("Morning"). Does anyone know what that means. -From our computer to yours- zach&kody

Member Avatar
Taywin
Posting Maven
2,632 posts since Apr 2010
Reputation Points: 134 [?]
Q&As Helped to Solve: 378 [?]
Skill Endorsements: 17 [?]
 
0
 

Which Timer class do you really want to use? Is it from javax.swing.Timer, java.util.Timer, or your own customized class? You may need to look at the classes' constructor. They are different.

By the way, implementing only ActionListener() inside the Morning class won't solve the whole problem if you still pass in the "Morning" class to the Timer as it is now.

Member Avatar
stevenwilson
Newbie Poster
1 post since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i love you zach

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: