• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing arrays as arguments

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finally got my first array problem solved (Thanks to all those that replied) and now have another!
I'm trying to use a Constructor that takes String arrays for argurments, and getting the error:
Incompatible type for constructor. Can't convert java.lang.String to java.lang.String[]
When I try to compile the calling class.
The constructor definition has the following format:

The call to create a new object has the following format:

The called class complies fine. I didn't originally the the 3's in the new myPanel statment, but the complier gave errors that it needed and index. After adding them, I get the error listed above.
Can anyone help??

[This message has been edited by Matthew Jones (edited January 10, 2001).]
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Matthew,
You don't say what ex1, ex2, and ex3 look like, but I'm assuming that they look something like this:

If that is the case, then your call to myPanel needs to look something like this:

In other words, you need to pass in a String[] instead of a String.
Susan
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi mattew,
by saying
new Myclass(ex[1]);
we are actually passing the first element from the array ex.
which in your case is a String.But the constructor out there is expecting an array of String and not just a String.
so this could solve ur problem.
new Myclass(ex);
hope this will help
thks
Vijay Pillai
 
Matthew Jones
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, it's working now!!!
I guess I thought that you had to specify you were passing in an array when you use the constructor, but now that I think about it, you don't have to specify what your passing in for anything else, so why should arrays be different?
Thanks again!
 
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic