Re: modify button
porky008 wrote:
porky008 wrote:
This is my modify button can some one help me get it right?
btnModify.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
dvds.add(DVD(tfTitle.getText(),Double.parseDouble(tfPrice.getText()),
Integer.parseInt(tfQuantity.getText())));
setList();;
}
});
...
..it is saying this when I run it
cannot find symbol
symbol: method DVD(java.lang.String,double,int)
dvds.add(DVD(tfTitle.getText(),Double.parseDouble(tfPrice.getText()),
^
Aaah.. It is probably that DVD(String, double) is a constructor,
right? To make a new instance of a DVD object.
In that case, the JVM thinks you are attempting to call a
DVD *method*, to clear its confusion, change it from..
dvds.add(DVD(tfTitle.getText(),
Double.parseDouble(tfPrice.getText()),
...to..
dvds.add(new DVD(tfTitle.getText(),
Double.parseDouble(tfPrice.getText()),
But a good *general* prinicple for debugging is not
to code like this in the first place. The code is attempting
to do too much in a single line, and it then becomes less
clear whcih part breaks. If I had problems with this code,
I might rewrite it something like this..
String priceText = tfPrice.getText();
// when in doubt, print out!
System.out.println("priceText: '" + priceText + "'");
double price = Double.parseDouble(priceText);
System.out.println("price: " + price);
DVD temp = new DVD(tfTitle.getText(), price);
System.out.println("DVD: " + temp);
dvds.add( temp );
...this way, would make it more clear, exactly
*where* the code was failing.
Note that a good debugger can do all that, much
quicker and without changing the code, but I think
it is important to understand how to plumb down
into a problem with minimal tools, to get training
for where/when to do it, and what to look for.
Andrew T.