Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 58
  1. #21
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Again, you can't call a method if it has not been defined. If we look at the FbRecords class, we see that there is a method with a similar name that does return a double value, getMbrship. So why not use it instead?
    Java Code:
    txtMnumber.setText(Double.toString(record.getMbrship()));
    Would that work in this place?

  2. #22
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Netbeans 6.5

    Yes that worked for the following

    Java Code:
    txtMnumber.setText(Double.toString(record.getMbrship()));
              txtRdate.setText(Double.toString(record.getDate()),

    However :confused:

    Java Code:
    txtBmi.setText(Double.toString(record.getBmi()));
    doesnt


    Sorry for the length of time its taking for this to sink in.

  3. #23
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    again, look at the error message as it will tell you (and us) what is wrong.

    My wife is now calling me to bed, and I don't dare refuse her. ;) Good luck and good night

  4. #24
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default Netbeans 6.5

    Sorry I missed off

    When I build and run I get

    run:
    Exception in thread "main" java.lang.NullPointerException
    at fatbustersasses3.frmBmi.<init>(frmBmi.java:29)
    at fatbustersasses3.Main.main(Main.java:22)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 3 seconds)
    However the only error I get is in the 1 line of code in message above

  5. #25
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Netbeans 6.5

    The error message I am getting within frmBmi is

    'void' type not allowed here

    with the following code

    Java Code:
    txtBmi.setText(Double.toString(record.getBmi()));
    Thanks again in advance

  6. #26
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Netbeans 6.5

    :confused:

    Can someone explain to me what these error messages mean

    (previous 2 messages).

  7. #27
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    show the latest incarnation of the program and please post the exact error messages. Again indicate which line is throwing the errors.

    The nullpointerexception, or NPE indicates that you are trying to call methods or access fields on an object that has not yet been constructed. You will need to look at all the objects on the line that calls this error to figure out which one is in a null state (has not been initialized).

  8. #28
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default Netbeans 6.5

    The error message is for the line of text highlighted in green, its the last of the three lines you were looking at yesterday

    Java Code:
                txtMnumber.setText(Double.toString(record.getMbrship()));
                txtRdate.setText(Double.toString(record.getDate()),
                txtBmi.setText(Double.toString(record.getBmindex()));
    Full code is

    Java Code:
              package fatbustersasses3;
              import java.text.*; // import library to enable 
              import java.io.*; // import libarary to enable input and output to a file
    
    /**
     *
     * @author 
     *
     * This is the .java file that drags all the information from the various class   files
     * FbRecords - Membership Records CLASS file
     * Conversion - Converts Mesurements and Weights ONLY
     * Formula - formula to calculate the BMI
     */
    
        public class frmBmi extends javax.swing.JFrame {
    
        ObjectOutputStream output;
        ObjectInputStream input;
        File file = new File(new File(getClass().getResource("membership").getFile()),"mbrship.txt");
    
    
        /** Creates new form frmBmi */
    
         private void cmdCloseAppActionPerformed(java.awt.event.ActionEvent evt) {                                            
          // Close Application:
             System.exit(0);
        }                                           
    
        private void cmdCalculateActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // TODO add your handling code here:
            // Variables using sensible nameing conventions
            double height;
            double weight;
            double outputBmi;
            String outbmi;
            boolean ok;
            ok = true;  //setting variable as valid to start
    //Start of try catch for non numeric data being entered in the height field
               try {
                    height = Double.parseDouble(txtHeight.getText());//expect numeric data only
                    weight = Double.parseDouble(txtWeight.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
                   }
    //End of height non numeric data try catch statement
    
    // try catch statements for height if under 100cm and over 300***************
    
                 try {
                        height = Double.parseDouble(txtHeight.getText());
                        //read from screen as integer
                     if (height > 300) throw new IllegalArgumentException("Maximum height of 300cm's");
                     // set a trap to catch numbers > 300
                     if (height < 100)  throw new IllegalArgumentException("Minimum height 100cm's");
                     // set a trap to catch numbers < 100
                     }
                        catch (NumberFormatException e)
                        // will catch the error if the input is not a number
                     {
                         Optpane.showMessageDialog(this,"Height between 100 + 300cm's","ERROR",Optpane.ERROR_MESSAGE);
                         ok=false;
                     }
                         catch (IllegalArgumentException e)
                         //will catch the errors outside of the parameters set
                     {
                         Optpane.showMessageDialog(this,e.getMessage(),"Error",Optpane.ERROR_MESSAGE);
                         ok=false;
                         // e.getMessage will get the message for e as set in the trap
                     }
    //end of height try catch statement***************
    
    // Start of weight try catch statement
                      try {
                            weight = Double.parseDouble(txtWeight.getText());
                            //read from screen as double
                                if (weight > 160) throw new IllegalArgumentException("Maximum Weight of 160Kg's");
                                // set a trap to catch numbers > 160
                                if (weight < 30)  throw new IllegalArgumentException("Minimum Weight 30Kg's");
                                // set a trap to catch numbers < 30
                        }
                        catch (NumberFormatException e)
                        // will catch the error if the input is not a number
                         {
                         Optpane.showMessageDialog(this,"Weight between 30 & 160Kg's","ERROR",Optpane.ERROR_MESSAGE);
                         ok=false;
                         }
                         catch (IllegalArgumentException e)
                         //will catch the errors as set up in the trap
                         {
                         Optpane.showMessageDialog(this,e.getMessage(),"Error",Optpane.ERROR_MESSAGE);
                         ok=false;
                         // e.getMessage will get the message for e as set in the trap
    // End of if statement for Weight
    
                         }
    
                         height=Double.parseDouble(txtHeight.getText());
                            weight=Double.parseDouble(txtWeight.getText());
    
                         outputBmi = Formula.bmi(height,weight);
    
                         txtBmi.setText(outbmi=bodymass.format(outputBmi));
    // End of BMI Formulae
    
    // If Statements for results : OK, OVERWEIGHT & UNDERWEIGHT
                        if (outputBmi < 18.5) { // need to add male or female and age to if statements
                        txtResults.setText("Underweight");
                     } else{
                            if (outputBmi > 24.9){
                                txtResults.setText("Overweight");
                     }           else
                                        txtResults.setText("OK");
                     }
    //End of if staements for txtResults
        }                                            
    
        private void cmdAddRecordActionPerformed(java.awt.event.ActionEvent evt) {                                             
            // Add record button code
            FbRecords record;
                try {
                record = new FbRecords(
                        Double.parseDouble(txtMnumber.getText()),
                        Double.parseDouble(txtRdate.getText()),
                        Double.parseDouble(txtBmi.getText()));
                output.writeObject(record); // writes the record
            }
    
            catch (IOException e) {
                Optpane.showMessageDialog(this, "Error adding a record","File Write Error",Optpane.ERROR_MESSAGE);
        }
            
    /* Clear cells after adding record*/
                         txtMnumber.setText("");
                         txtRdate.setText("");
                         txtBmi.setText("");
                         txtGender.setText("");
                         txtAge.setText("");
                         txtHeight.setText("");
                         txtHconversion.setText("");
                         txtWeight.setText("");
                         txtWconversion.setText("");
                         txtResults.setText("");
        }                                            
    
        private void cmdNewFileActionPerformed(java.awt.event.ActionEvent evt) {                                           
     // Creates new file on press of the new button
            try{
                 output = new ObjectOutputStream(new FileOutputStream(file)); }
                 catch (IOException e) {
                 Optpane.showMessageDialog(this, "error with the input file", "File Error", Optpane.ERROR_MESSAGE);
                 }
    
    /* Disables Add before the file has been created */
                 cmdAddRecord.setEnabled(true);
    
        }                                          
    
        private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {                                        
             // Next Button code
              FbRecords record;
            //reads the ‘next record’ ie file is already open from reading the first record
            try {
                //file is already open
                record = (FbRecords)input.readObject();  //read whole record
                // put record fields in to the screen fields
                txtMnumber.setText(Double.toString(record.getMbrship()));
                txtRdate.setText(Double.toString(record.getDate()),
                txtBmi.setText(Double.toString(record.getBmindex()));
            
                }
    
            catch (IOException e) {            
                Optpane.showMessageDialog(this, "IO Error reading file, possible EOF","File Read Error",Optpane.ERROR_MESSAGE);
                cmdNext.setEnabled(false);  //this should disable the next button on the last record so u dont get EOF error message
                cmdAddRecord.setEnabled(false); // Disables next but still displays EOF error message.
            }
            catch (ClassNotFoundException e) {
                Optpane.showMessageDialog(this, "Class Error reading next record","File Read Error",Optpane.ERROR_MESSAGE);
            }
    
    }                                       
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new frmBmi().setVisible(true);
                }
            });
        }
    Thanks in advance!

  9. #29
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    The exact error message I am getting is

    'void' type not allowed here

    ')' expected


    txtMnumber.setText(Double.toString(record.getMbrsh ip()));
    txtRdate.setText(Double.toString(record.getDate()) ,
    txtBmi.setText(Double.toString(record.getBmindex() ));

  10. #30
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    so, the question you must ask yourself, where do you see the term void? what in general sometimes returns void? This is not a question yet over your code, but just a question to educate you on Java in general: Again, where in Java in general do you see the term void being used?

  11. #31
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    The term void is used for each section/button

    In this case

    private void cmdNextActionPerformed(java.awt.event.ActionEvent evt) {
    and for each button on my app

  12. #32
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    In general void is the return type of a method that in fact is returning nothing. Back in my Pascal/Delphi days, we'd call these methods "procedures" and methods that returned things like doubles and whatnot we'd call "functions".

    So now we know where and how void is used, let's see if it's being misused. The error message is telling us that a method that is being called on that line is returning void when it should be returning something else such as a double. Which method(s) could possibly be the offending one?

  13. #33
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Netbeans 6.5

    Well as the DoubletoString seems to be causing the problem in the code

    Java Code:
    txtBmi.setText(Double.toString(record.getBmindex()));
    But as I want this information returned from a text file isnt this the only way that I can do this?

  14. #34
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    No, Double.toString is working well in this position. it's another method. What is being called from inside the Double.toString parameter? it's record.getBmindex()? Could this method be the problem?

    Your job: check the code for the class that record belongs to, I believe that it's FbRecords, and look at the getBmindex() method. Does it exist? what does it return? Is it a double value or is it void?

  15. #35
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question Netbeans 6.5

    Well

    fbRecords has the following

    Java Code:
    public FbRecords(double m, double d, double b) {
              setMbrship(m);
              setDate (d);
              setBmindex(b);
    Java Code:
    public void setBmindex(double b){
              bmi = b;
              }
    
              public double getBmindex(){
              return bmi; // gets data from file to return to GUI
              }
    so Bmindex is in the class file

    and from the app code :

    Java Code:
    txtBmi.setText(Double.toString(record.getBmindex()));
    Now to me apart from possible brackets missing or something I see the right referance.

    When you say look at the Bmindex section it is correct yes?

  16. #36
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    Well I have tried to work out exactly what it is your asking me to look for.

    As far as I can see the class with the Bmindex is returning something.

    If I was able to run the application by pressing the NEXT button it would go on to the second record and so on.

    If I am not answering what you are asking me maybe try again?

  17. #37
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm at a loss. Perhaps you need to post your entire code. If so, perhaps package it together in either a zip file or jar file.

  18. #38
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Question

    I have posted the complete project zipped, the other classes other than the ones mentioned are empty though as there is a lot more to do after this issue.

    Thanks for any help and or guidance in advance,
    Attached Files Attached Files

  19. #39
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The above code doesn't show the changes we made to your bad constructor call near the beginning of this thread, nor the bad method calls we fixed here later. Also, is there also a data file that is needed for this to run?

  20. #40
    dbashby's Avatar
    dbashby is offline Senior Member
    Join Date
    Mar 2009
    Posts
    223
    Rep Power
    6

    Default

    No there is no data file for this as I am running through netbeans.

    As far as the changes, yes the zipped file has all the changes suggested such as the methods etc

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Hi Am New To Use Netbeans
    By arunkumarinfo in forum NetBeans
    Replies: 1
    Last Post: 01-23-2009, 05:18 AM
  2. Need Help in Netbeans please
    By Akora in forum New To Java
    Replies: 3
    Last Post: 01-21-2009, 06:43 PM
  3. cannot run web app with Netbeans
    By CirKuT in forum New To Java
    Replies: 5
    Last Post: 10-28-2008, 04:48 PM
  4. netbeans
    By sweet angle in forum NetBeans
    Replies: 1
    Last Post: 08-05-2008, 05:06 AM
  5. netbeans 64 bit
    By caspermel in forum NetBeans
    Replies: 1
    Last Post: 06-26-2007, 11:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •