Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cannot resolve symbol errors

Status
Not open for further replies.

rbr19

Programmer
Jun 2, 2004
4
GB
hi all,

i'm getting 2 cannot resolve symbol errors after i compiled my code. the full description of the errors are as below:

1. cannot resolve symbol
symbol: method addData (MyData)
location: class javax.swing.JPanel
centerPanel.addData(new MyData(""));
^
2. cannot resolve symbol
symbol : method addData (MyData)
location: class javax.swing.JPanel
centerPanel.addData(new MyData
(materialx.getSelectedItem().toString()));
^

i have a shorter version of this code & it worked. after i made some modifications like adding another jbutton & jcombobox then i started getting these errors. i must have made a few errors but unfortunately i just cannot figure out where i went wrong.

i would really appreciate if any of you guys can help me on this. thanks in advance.

below is my code:

Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.awt.Graphics.*;
import java.util.ArrayList;

public class Testing extends JFrame implements ActionListener
{
    
String  x[] = { " ", "Material A", "Material B", "Material C"};
String  y[] = { "                       ", "+5", "+4", "+3", "+2", "+1", " 0", "-1", "-2", "-3", "-2", "-5" };
    
    private JButton Plot, End;
    private Container c;
    private JPanel centerPanel, northPanel, southPanel;
    private JComboBox materialx, materialRatingy;  
    MyGraph mg = new MyGraph();
       
   public Testing()
   {
      super( "Welcome" );
     
	  Container c = getContentPane(); 
	  centerPanel.addData(new MyData(""));
	  centerPanel = new JPanel();
	  centerPanel.setBackground(Color.white);
      	  c.add( centerPanel, BorderLayout.CENTER);
      	  setVisible(true);

northPanel = new JPanel();
northPanel.add(new Label( "Please choose accordingly:" ));
northPanel.setLayout (new FlowLayout(FlowLayout.CENTER, 20, 0));
          
    materialx = new JComboBox( x );
    materialx.setMaximumRowCount( 2 );
    materialx.setBorder  
   (BorderFactory.createTitledBorder("Design Materials"));
    northPanel.add( materialx );
    materialx.setEditable(true);
         
 materialRatingy = new JComboBox( y );
 materialRatingy.setMaximumRowCount( 2 );
 materialRatingy.setBorder(BorderFactory.createTitledBorder("Material Ratings"));
 northPanel.add( materialRatingy );
                 
         c.add( northPanel, BorderLayout.NORTH );
         setVisible( true );
         
         southPanel = new JPanel();
         Plot = new JButton( "Plot" );
         End = new JButton( "End" );
         
         southPanel.add( Plot );
         southPanel.add( End );
        
         c.add( southPanel, BorderLayout.SOUTH );
         setVisible( true );
         
         Plot.addActionListener(this);
         End.addActionListener(this);
         
         Plot.addActionListener(new ActionListener() 
   		{
        public void actionPerformed(ActionEvent e) 
        {
        
centerPanel.addData(new MyData(materialx.getSelectedItem().toString()));
centerPanel.repaint();
        }
        });
                                  
        pack();
       }
   
 public static void main( String args[] )
   {
      Testing app = new Testing();
      app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

   }
   
   public void actionPerformed(ActionEvent e)
   {
   	if(e.getSource()==Plot)
 
   	{
   		System.out.println("Plot");
   	}

   else if(e.getSource()==End)
   	{
   		System.exit(0);
   	}
   }
   
} 
class MyGraph extends JPanel 
{
  ArrayList al = new ArrayList();
  public void addData(MyData data) 
  { al.add(data); }
  public void paintComponent(Graphics g) 
  {
    Graphics2D g2d = (Graphics2D)g;
    super.paintComponent(g);
       
        for (int i=0; i<al.size(); i++) 
        {
        MyData md = (MyData)al.get(i);
        g.setColor(Color.blue);
        g.drawRect(120+i*20, 120, 20, 200);
        g.drawString ("Material", 30, 220);
        g.drawString ("Ratings", 30, 240);
        g.drawString ("+5", 102, 130);
        g.drawString ("0", 107, 220);
        g.drawString ("-5", 102, 315);
        
        g.setColor(Color.red);
	g.drawRect(120+i*20, 321, 20, 200);
	g.drawString ("Design", 30, 410);
	g.drawString ("Materials", 30, 430);
        }
        
        g2d.rotate(-Math.PI/2.0,250,250);
        g.setColor(Color.blue);
        
        for (int i=0; i<al.size(); i++) 
        {
        MyData md = (MyData)al.get(i);
        g2d.drawString(md.getMaterial(),-15,15+i*20);
        }
  }
}
class MyData {
  String material;
  
  public MyData(String material) {
    this.material=material;
    
  }
  public String getMaterial() { return material; }
  
}
 
Well there is no such method as "addData()" for a JPanel object (in this line) :

centerPanel.addData(new MyData(""));

--------------------------------------------------
Free Database Connection Pooling Software
 
The problem is the function call "addData()"

---> centerPanel.addData()

There is no "addData" method defined? centerPanel is a JPanel which doesn't have a signature addData(MyData ).

if you take out the two statement that calls addData, the code will compile. What are you try to achieve with "addData"?
 
byam :
I reckon we were posting at the same time there fella !

If you're in Europe, its bed time, and if you're in the US, its too early on a Sunday to be tek-tipping !! :)

( UK, GMT 01.43.00 )

--------------------------------------------------
Free Database Connection Pooling Software
 
million thanks for the replies sedj & byam. i really appreciate it. i've managed to solve the problem. i've made some changes like:

1. i changed //centerPanel.addData(new MyData("")); to
mg.addData(new MyData(""));

2. i added mg.setBackground(Color.white); &
c.add( mg, BorderLayout.CENTER);

3. i changed //centerPanel.addData(new MyData(
materialx.getSelectedItem().toString())); to
mg.addData(new MyData(materialx.getSelectedItem().toString()));

4. i changed //centerPanel.repaint(); to
mg.repaint();

below is the code after i made the changes.

Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.awt.Graphics.*;
import java.util.ArrayList;

public class Testing extends JFrame implements ActionListener
{
    
String  x[] = { " ", "Material A", "Material B", "Material C"};
String  y[] = { "                       ", "+5", "+4", "+3", "+2", "+1", " 0", 
    						"-1", "-2", "-3", "-2", "-5" };
    
    private JButton Plot, End;
    private Container c;
    private JPanel centerPanel, northPanel, southPanel;
    private JComboBox materialx, materialRatingy;  
    MyGraph mg = new MyGraph();
       
   public Testing()
   {
      super( "Welcome" );
     
	  Container c = getContentPane();
	  //centerPanel.addData(new MyData(""));
      mg.addData(new MyData(""));
	  centerPanel = new JPanel();
	  
	  
	   	
	  	 centerPanel.setBackground(Color.white);
      	 c.add( centerPanel, BorderLayout.CENTER);
      	 mg.setBackground(Color.white);
      	 c.add( mg, BorderLayout.CENTER);
      	 setVisible(true);
	 
	  	 northPanel = new JPanel();
   		 northPanel.add(new Label( "Please choose accordingly:" ));
   	     northPanel.setLayout (new FlowLayout(FlowLayout.CENTER, 20, 0));
          
         materialx = new JComboBox( x );
         materialx.setMaximumRowCount( 2 );
         materialx.setBorder(BorderFactory.createTitledBorder("Design Materials"));
         northPanel.add( materialx );
         materialx.setEditable(true);
         
         materialRatingy = new JComboBox( y );
         materialRatingy.setMaximumRowCount( 2 );
         materialRatingy.setBorder(BorderFactory.createTitledBorder("Material Ratings"));
         northPanel.add( materialRatingy );
                 
         c.add( northPanel, BorderLayout.NORTH );
         setVisible( true );
         
         southPanel = new JPanel();
         Plot = new JButton( "Plot" );
         End = new JButton( "End" );
         
         southPanel.add( Plot );
         southPanel.add( End );
        
         c.add( southPanel, BorderLayout.SOUTH );
         setVisible( true );
         
         Plot.addActionListener(this);
         End.addActionListener(this);
         
         
         
        Plot.addActionListener(new ActionListener() 
   		{
        public void actionPerformed(ActionEvent e) 
        {
        
        //centerPanel.addData(new MyData(materialx.getSelectedItem().toString()));
        //centerPanel.repaint();
        mg.addData(new MyData(materialx.getSelectedItem().toString()));
        mg.repaint();
        }
        });
                                  
        pack();
                                
 }
   
 
   public static void main( String args[] )
   {
      Testing app = new Testing();
      app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

   }
   
   public void actionPerformed(ActionEvent e)
   {
   	
   	if(e.getSource()==Plot)
 
   	{
   		System.out.println("Plot");
   	}

   else if(e.getSource()==End)
   	{
   		System.exit(0);
   	}
   }
   
} 
class MyGraph extends JPanel 
{
  ArrayList al = new ArrayList();
  public void addData(MyData data) 
  { al.add(data); }
  public void paintComponent(Graphics g) 
  {
    Graphics2D g2d = (Graphics2D)g;
    super.paintComponent(g);
       
        g.setColor(Color.blue);
        g.drawString ("Material", 30, 220);
        g.drawString ("Ratings", 30, 240);
        g.drawString ("+5", 102, 130);
        g.drawString ("0", 107, 220);
        g.drawString ("-5", 102, 315);
        
        g.setColor(Color.red);
        g.drawString ("Design", 30, 410);
		g.drawString ("Materials", 30, 430);
        
            
        for (int i=0; i<al.size(); i++) 
        {
        MyData md = (MyData)al.get(i);
        g.setColor(Color.blue);
        g.drawRect(120+i*20, 120, 20, 200);
        
        
        g.setColor(Color.red);
		g.drawRect(120+i*20, 321, 20, 200);
		
        }
        
        g2d.rotate(-Math.PI/2.0,250,250);
        g.setColor(Color.blue);
        
        for (int i=0; i<al.size(); i++) 
        {
        MyData md = (MyData)al.get(i);
        g2d.drawString(md.getMaterial(), -15, 135+i*20);
        }
  }
}
class MyData {
  String material;
  
  public MyData(String material) {
    this.material=material;
    
  }
  public String getMaterial() { return material; }
  
}

ps: you are right sedj...it is bed time in the uk (uk gmt 02.25.00) i should be in bed some 2-3 hrs ago! thanks for reminding :) anyway cheers mate!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top