aspose file tools*
The moose likes Java in General and the fly likes Resolving conflict between constructor and method call in main class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Resolving conflict between constructor and method call in main class" Watch "Resolving conflict between constructor and method call in main class" New topic
Author

Resolving conflict between constructor and method call in main class

celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I've written a Title, TitleList and a main class to test these. The problem occurs between the constructors in the Title class and the test maim class. the constructors are as follows,

I need to call the above constructor in the test main class in conjunction with an add method from the TitleList class. The problem is that when the user runs the main class they have to input an integer and four strings. These strings can be any number of words per input.

How do I use the following main class with the above constructors?


Any idea how to use the user input of one integer and four strings with the constructors in the Title class?

Any help or advice gratefully appreciated!!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Assuming you lost this line in a typing this in ...

public Title( String filmDetails )

That constructor expects the five fields you have collected in one string with commas between them. Could you build one string like that from your fields?

The other constructor expects a SimpleReader that is ready to read the five fields in a single line. That could work, but you'd have to make sure your user is willing and able to type all five fields correctly with commas between them.

With either constructor, watch out for titles with commas in them! "The Good, the Bad and the Ugly" is going to be too complex for this program.

So try building one string from your five fields and show us how it goes!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

Thanks for the help. I'm able to build one string from many using an example such as,

The problem is that I'm still getting errors from my main class. I get the following error,

These errors refer to the following code. Firstly within the Title class,

and secondly within the main class,

I'm assuming the second error is simply because of the first problem in the Title class.

Anybody know why this happening and what it means?
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I'm happy to say I've nearly solved this problem. I now have the file being written and read correctly, up to the time the user inputs and saves the data on the third try. Then the previous line is saved with an extra comma after the first integer, as follows


Does anybody know why this might happen?

The current code for my main class is as follows,

Any help or advice?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18988
    
  40

It doesn't look like an extra comma to me -- as all lines have the same amount of commas.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

Yes, I think you're right. Whenever I try to add an extra title, it writes the first entry correctly, and then moves the first string to the second string postion in the list, leaving the first sting position empty, as follows,


Does anybody know why this might happen?
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I'm very pleased to announce that this problem has finally been solved. I've added some extra code to the split method within the first constructor in the Title class. Code is as follows,

Thanks for all the help!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Resolving conflict between constructor and method call in main class