HI,I made this small calculator which asks yser to enter two number and then performs the operation selected by user on clicking the button on the form.but it is giving error.The error comes when I want to write on the text field.Another error is the NullpointerException in main thread.How can i solve this problem.the code is as following: Thanks in advance
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
t3.setText(valueOf(z));
setText() requires a String argument. what is valueOf(..)? is it your own method? perhaps it should be String.valueOf(..)
next problem JPanel p; ... getContentPane().add(p);
somewhere, in between the declaration and its use, you will need p = new JPanel(); //and set the layout if not FlowLayout
these will cause you problems in actionPerformed change them to b1 = new JButton("+"); b2 = new JButton("-"); b3 = new JButton("*"); b4 = new JButton("/"); b5 = new JButton("quit");
[EDIT] - same for the JTextFields, and the JLabels [ April 15, 2006: Message edited by: Michael Dunn ]
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32610
4
posted
0
I have come to the conclusion that there are three Exceptions which should not be tolerated:-
They all mean you need to go back to your code and find out what you ahve done wrong. In your case, you don't tell us what sort of error messages you are getting. What are you getting from your compiler? Have you put in a method without its class? In the case of your NullPointerException, go to the line in question, and immediately before it put in a line like this: System.out.printf("this: %s, p %s%n", this, p);//test What that will do is print out the "toString()" method of each of the objects which might or might not be null. You will get a printout something like this:-
this: calcu 8a2dfc7, f: null
One of those is the name of the class with its hashcode, the other is null. Whichever of the two comes out as null, go back and find it, then:-
Check you haven't declared it twice by mistake; if you declare