Results 1 to 7 of 7
- 03-19-2009, 05:23 PM #1
[SOLVED] Simple Conversion Calculator
I have put together a small application converting cm to inches, however I need help resolving 1 error.
I cannot seem to work out what I have done wrong and would appreciate it if you could take a look, I know it is a simple error but I cannot work it out.
Thanks in advance for your help
File attached
- 03-19-2009, 05:30 PM #2
Simple Conversion Calculator
Just incase you dont want to download the file, the formula is in a class
Class - Units
GUI - Application
Netbeans 6.5 was used
code that is causing me the problem is
The line causng the problem is highlighted in green.Java Code:package conversion; import java.text.*; /** * * @author Admin */ public class Application extends javax.swing.JFrame { /** Creates new form Application */ public Application() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void cmdConvertActionPerformed (java.awt.event.ActionEvent evt) { // Code for converting. CM TO INCHES - txtInch txtCm double inch; double cm; double outputInches; boolean ok; ok = true; String outinch; // try catch for numeric data only try { cm = Double.parseDouble(txtCm.getText());//expect any numerical input } catch (NumberFormatException n) {//to catch none numeric input Optpane.showMessageDialog(this,"Enter numbers only please", "please re-enter",Optpane.ERROR_MESSAGE); // Optpane kicks in on error ok = false; //boolean to trigger Optpane on alpha entry } // start of formula to convert cm to inches and inches to cm - uses class file Units.java cm=Double.parseDouble(txtCm.getText()); [COLOR="Green"]outputInches = Units.conversion(cm,inch);[/COLOR] txtInch.setText(outinch=conversions.format(outputInches)); // End of formula
- 03-19-2009, 07:24 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 79
- Rep Power
- 0
What error do you get?
I would guess a NullPointerExption because Units is not created.
- 03-19-2009, 08:59 PM #4
Senior Member
- Join Date
- Nov 2007
- Posts
- 160
- Rep Power
- 6
I think the problem is your last statement, a part of which is 'conversions.format(...'
What is 'conversions?'
@bubbless
I don't think so, because Units is a reference to that class, not an object. He just has to ensure that the conversion method in Units is static.
-
Your problem is that Java is case sensitive. Conversion is not the same as conversion. I'd change the case of the method in the Units class to be all lower-case.
In other words, change this:
to this:Java Code:public static double Conversion(double cm, double inch) { //.... some code }
Edit: also, what are you doing with the inches parameter in your conversion method, and the inches variable in your Application class. They both seem superfluous.Java Code:public static double conversion(double cm, double inch) { //.... some code }Last edited by Fubarable; 03-19-2009 at 10:24 PM.
- 03-20-2009, 12:40 AM #6
Calculator
I managed to solve the issue then I also put a calculator as a seperate package together converting the other way round inches to cm
Thanks for your replies.
See attached
-
Similar Threads
-
Calculator program
By kevzspeare in forum New To JavaReplies: 6Last Post: 03-18-2009, 01:43 PM -
[SOLVED] Simple Calculator Applet Weird Error
By sari in forum New To JavaReplies: 5Last Post: 01-28-2009, 04:57 AM -
Calculator help.
By madkidd02 in forum New To JavaReplies: 2Last Post: 10-25-2008, 07:42 AM -
Java Calculator
By aapanju in forum New To JavaReplies: 3Last Post: 04-17-2008, 05:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks