error symbol : constructor WWLTableModel() -->how to call a class

trying to call a class of different filename from main program (filena

Page 1 of 1

1 Replies - 1051 Views - Last Post: 13 September 2007 - 05:24 PM Rate Topic: -----

#1 nastassja_hong  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 13-September 07

error symbol : constructor WWLTableModel() -->how to call a class

Post icon  Posted 13 September 2007 - 03:04 PM

my main program is called SP.java with GUI and i created another class WWLTableModel.java. i would like to call the WWLTableModel class from my main program and i tried using the below codings

	private void createSetComparison (){
		WWLTableModel[] wwlTM = new WWLTableModel [map.size()]; //create a Set of array and store in WWLTableModel
		
		Set set1 = map.entrySet();
		Iterator iteratorSet1 = set1.iterator();
		int a = 0;
		
		
		while (iteratorSet1.hasNext()){
			wwlTM[a]= new WWLTableModel(); //-->error appears here
			
		}
		
	}



but there is an error on the code lined wwlTM[a]= new WWLTableModel(); after compilation, which says

symbol : constructor WWLTableModel()
location: class WWLTableModel
wwlTM[a]= new WWLTableModel();

how do i solve this problem?? in other words, how do i call the class WWLTableModel from my main program??

Is This A Good Question/Topic? 0
  • +

Replies To: error symbol : constructor WWLTableModel() -->how to call a class

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4421
  • View blog
  • Posts: 12,286
  • Joined: 18-April 07

Re: error symbol : constructor WWLTableModel() -->how to call a class

Posted 13 September 2007 - 05:24 PM

First of all make sure you have your class in the same directory as your main program (I don't think this is your real problem but it is just to make sure). Secondly, did you define constructors in your class? I am betting you did but you forgot to create a default constructor. Remember, if you chose to create constructors you must also define a default constructor if you intend to use one... which you are with the line you are using.

public class blah {
	public blah() { System.out.println("now works"); }
	public blah(int i) { System.out.println("Testing"); }
}



If I was to take out the default constructor I have defined above (the one that reads "now works") and then try to create a new object using the default constructor it would error out...

// Errors out if I only had blah(int i) defined and no default constructor.
blah myblah = new blah(); 



So go back and look at your class. I am sure you will find it missing a default constructor. Either put one in or back in your main program instead of using just new WWLTableModel(); use one of your constructors that takes parameters.

Hope this makes sense to you! :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1