aspose file tools*
The moose likes Beginning Java and the fly likes Problem with ArrayList toArray method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with ArrayList toArray method " Watch "Problem with ArrayList toArray method " New topic
Author

Problem with ArrayList toArray method

Brett Wiggins
Greenhorn

Joined: Mar 23, 2009
Posts: 19
Hi,

I am having some problems getting an array from an ArrayList. My code is as follows;



That seems to be fine but when I try and use the array as a constructor argument;



I get;



any help would be cool.
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

is unitCode,unitTitle are String ? and type is courseType?

It will be easy if you show the code of constructor Unit(...)


Life is easy because we write the source code.....
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Can you show us the constructors of your Unit class ?


[My Blog]
All roads lead to JavaRanch
Brett Wiggins
Greenhorn

Joined: Mar 23, 2009
Posts: 19
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

what about Pramod's question ? is unitCode,unitTitle are String ? and type is unitType ?
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
Looks like the problem is in the third parameter. The constructor expects the third parameter to be a unitType, but you're trying to pass in a courseType.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
The types that the constructor expects were defined in the constructor, just shown. The types that were being passed in were revealed in the error message:

This tells us it's looking for a Unit constructor that takes (String, String, courseType, Campus[]), but it can't find that combination.

By the way, it's generally a bad idea to have class names that begin with lowercase letters. They defy well-established standard convention. The compiler doesn't care, but such names tend to mislead the humans who look at your code and try to help you. Class names are expected to begin in uppercase; variable names begin with lowercase.
Brett Wiggins
Greenhorn

Joined: Mar 23, 2009
Posts: 19
Pramod P Deore wrote:is unitCode,unitTitle are String ? and type is courseType?

It will be easy if you show the code of constructor Unit(...)


they are Strings', the type and CourseType refer to enums. Thankyou for your help. I have fixed the problem
Brett Wiggins
Greenhorn

Joined: Mar 23, 2009
Posts: 19
Thanks for all the help. I had two different enums. unitType and courseType. I have replaced the two enums with just one and it has worked
like magic and fixed the problem. Everyone here seems to be noob friendly.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3014
    
  10
Wait, you're a noob? Crap. There goes the neighborhood...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with ArrayList toArray method