aspose file tools*
The moose likes Beginning Java and the fly likes To fix an ArrayList API problem.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "To fix an ArrayList API problem...." Watch "To fix an ArrayList API problem...." New topic
Author

To fix an ArrayList API problem....

S. S. Diaz
Greenhorn

Joined: Jul 18, 2006
Posts: 6
Hello there!...I have an ArrayList problem(or defect) in Java because everytime this code snippet:

numReg.add(a);

inside the inner class runs, the object "a"(a double variable) won't add to the ArrayList. Is there anything that I can do to solve the problem? Here are my code fragments that is supposed to function well for my calculator project:

class subtractNum implements ActionListener { // an inner class for
// the subtraction.

public void actionPerformed(ActionEvent event){
if(!(numReg.contains(a))){
a = Double.parseDouble(field.getText());
numReg.add(a);
field.setText("0");
op = "-";
} else {
if (op == "-") {
a = a - Double.parseDouble(field.getText());
} else {
if (op == "+"){
a = a + Double.parseDouble(field.getText());
}
if (op == "*"){
a = a * Double.parseDouble(field.getText());
}
if (op == "/"){
a = a / Double.parseDouble(field.getText());
}
}
field.setText(a + "");
op = "-";
b = Double.parseDouble(field.getText());

}
new NumButtonPackage();
numReg.remove(b);
}
}

Thankz in advance!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Hi, this is a JSP forum, post to the beginner forum next time

Why is "a" removed ? Maybe this could be a hint :

numReg.add(a);
field.setText(a + "");
b = Double.parseDouble(field.getText());
numReg.remove(b);


[My Blog]
All roads lead to JavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Moving to Java In General (Beginner)


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112


Are you aware of the fact that the value of "a" changes between the check in the if and the call to add?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To fix an ArrayList API problem....