• 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

Common class to remove redundant code

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got two separate classes that have very similar code and I'm trying to create a common class that they can use to get rid of any redundant code but I'm really having some trouble. Here is the code that the two classes share. As you can see they are similar but not exactly the same.



Here is the code in the "common" class I'm trying to create:


So now when I want to use the common class I try something like this:


When I try to use this I get an error: Could not find matching constructor for: Fragments. Any help is greatly appreciated!
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please UseCodeTags (← click) when posting code as it makes it easier for people to read your code. I've added them for you this time.

When I try to use this I get an error: Could not find matching constructor for: Fragments.


Your problem is because your Fragments class only has a no args constructor but you are trying to create an instance of Fragments passing in 3 arguments.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've just noticed that none of the code supplied will even compile. Can you explain what each of the code fragments is supposed to do.
 
Delmon Wright
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whoops sorry Tony, I'm obviously a newb. What the first two methods do is takes the current page a user is on and adds a "#" + what the user supplied in a dialog. So the end output of the first two methods is something like "contact.html#something". This works just fine and I'm simply trying to create a common class that shares this functionality cause it doesn't make sense to have virtually the same code in two different places. When I add a third parameter I seem to get the same error message as I did with 2 parameters. Thanks for the help!
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless you show compilable code you say is working and the actual code that won't compile and the compilation error message it's a bit difficult to help you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic