| Author |
getter not running
|
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
my class Recipes has a getter to take various data, in a window i create an instance of Recipes and i try to get the "name", but if i create the file with those value, there is no value. the file is created, but empty
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24039
|
|
When a recipe is created, the recipeName passed to the constructor comes from the member variable recipeName in NewJDialog. I don't see where anything ever sets that value to a non-empty String. the NewJDialog class has a constructor that accepts a recipeName argument, but (1) nothing ever calls it, and (2) the constructor ignores the arguments anyway. Therefore the Recipe is created with "" as a recipeName, and that's what you get back when you call getRecipeName().
Where do you expect the name to be coming from?
|
[Jess in Action][AskingGoodQuestions]
|
 |
deepak kushwaha
Ranch Hand
Joined: Jul 17, 2010
Posts: 33
|
|
private String ingredients[]; <<isnt this giving you an error!!!how can you
make a String of an object !!!
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
Ernest Friedman-Hill wrote:When a recipe is created, the recipeName passed to the constructor comes from the member variable recipeName in NewJDialog. I don't see where anything ever sets that value to a non-empty String. the NewJDialog class has a constructor that accepts a recipeName argument, but (1) nothing ever calls it, and (2) the constructor ignores the arguments anyway. Therefore the Recipe is created with "" as a recipeName, and that's what you get back when you call getRecipeName().
Where do you expect the name to be coming from?
i forgot to add :P i added now but the file created is empty
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
deepak kushwaha wrote:private String ingredients[]; <<isnt this giving you an error!!!how can you
make a String of an object !!!
is a simple string array
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24039
|
|
deepak kushwaha wrote:private String ingredients[]; <<isnt this giving you an error!!!how can you
make a String of an object !!!
This is a perfectly valid declaration for a variable that holds an array of Strings. You can write it as either
private String[] ingredients;
or
private String ingredients[];
Both mean exactly the same thing.
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
|
yes i have no error now, but the file i try to create, is created but empty
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24039
|
|
|
Well, as I said, the recipeName is never getting set to a non-empty value; the same holds for the other members, I would guess.
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
Ernest Friedman-Hill wrote:Well, as I said, the recipeName is never getting set to a non-empty value; the same holds for the other members, I would guess.
no read again, i fixed that,
before to create the file i made a print of value to put in file, and the value are ok, but the file is the same empty
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24039
|
|
|
Well, there's an empty catch block in the "try" around the file writing code. That means if something fails, you won't hear about it. Empty catch blocks are murderous evil -- always at least include a printStackTrace() so you can see what happened! Add this, and see if you get an error message.
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
solved that thing
now i get this error while working on some number value
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
at java.util.Vector.elementAt(Vector.java:427)
at javax.swing.DefaultListModel.getElementAt(DefaultListModel.java:70)
at desktopapplication1.NewJDialog.jButton2_addActionPerformed(NewJDialog.java:168)
at desktopapplication1.NewJDialog.access$100(NewJDialog.java:22)
at desktopapplication1.NewJDialog$2.actionPerformed(NewJDialog.java:86)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
what is it?
|
 |
Michael Montean
Greenhorn
Joined: Jul 19, 2010
Posts: 1
|
|
your loop is going out of bounds on the index.
Java index starts at 0 in an array. Therefore an array of size 10 would have a maximum index of 9.
Your code says
c will be greater than the maximum index in the array on the last iteration. You need to say,
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
Welcome to the Ranch Michael Montean
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
ty i corrected the index but still an error
while ( c < jList1.getModel().getSize() ) {
System.out.println(c+"<"+jList1.getModel().getSize());
System.out.println(jList1.getModel().getElementAt(c));
ingredients[c] = (String)jList1.getModel().getElementAt(c);
c++;
}
this code, stamp just the first value of the list
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
ty i corrected the index but still an error
while ( c < jList1.getModel().getSize() ) {
System.out.println(c+"<"+jList1.getModel().getSize());
System.out.println(jList1.getModel().getElementAt(c));
ingredients[c] = (String)jList1.getModel().getElementAt(c);
c++;
}
this code, stamp just the first value of the list
this is how i edited, but still doesnt work, just stamp the first raw of jList, if i put setingredient((string= string under comment, it works,why???'
|
 |
Jan Hoppmann
Ranch Hand
Joined: Jul 19, 2010
Posts: 98
|
|
|
I don't see a method setIngredient(String, int) in your Recipes class - perhaps you forgot to write it?
|
Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
sorry i edited the class and didnt updated on here, this is the class Recipes
|
 |
Jan Hoppmann
Ranch Hand
Joined: Jul 19, 2010
Posts: 98
|
|
|
I can't see anything wrong. Do you get any runtime errors or warnings during compilation?
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
Jan Hoppmann wrote:I can't see anything wrong. Do you get any runtime errors or warnings during compilation?
no is really strange
when i made the stamp of the while, the while run just the first iteration if i have the command that assign the value of the list to the array
|
 |
Antony Amicone
Ranch Hand
Joined: Mar 11, 2006
Posts: 125
|
|
|
please helppppppppp i need to finish soon this program and this thing is blocking me
|
 |
 |
|
|
subject: getter not running
|
|
|