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

    Default

    No there is no data file for this as I am running through netbeans.
    It seems that it does, as it throws an exception that was only corrected by my creating a file called "dataFiles" and placing it in the class's directory.

    As far as the changes, yes the zipped file has all the changes suggested such as the methods etc
    I'm not sure on this either. The zipped files had this construct, one that I thought we had fixed earlier:
    Java Code:
                record = new mbrRecord(
                        Double.parseDouble(txtMnumber.getText()));
                        Double.parseDouble(txtRdate.getText());
                        Double.parseDouble(txtBmi.getText());
                        output.writeObject(record); // writes the record
    as well as the commented out code that I've corrected here:
    Java Code:
          /*
          txtMnumber.setText(Double.toString(record.getMnumber()));
          txtRdate.setText(Double.toString(record.getRdate()));
          txtBmi.setText(Double.toString(record.getBmi()));
           */
          
          txtMnumber.setText(Double.toString(record.getMembership()));
          txtRdate.setText(Double.toString(record.getDate()));
          txtBmi.setText(Double.toString(record.getBmindex()));
    But I think that I've fixed them, and the GUI at least displays for me. Is the GUI at least displaying for you?

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

    Question

    Sorry I seem to be more confused now, I went back to when you gave me the first solution at the start of this thread and you suggested

    Java Code:
              record = new bmiRecord(
                        Double.parseDouble(txtMembership.getText()), 
                        Double.parseDouble(txtDate.getText()), 
                        Double.parseDouble(txtBmi.getText()));
              output.writeObject(record); // writes the record
    this is what should be in the zipped file I attached.

    At this moment no I cannot get it to run without errors, it will run but I get a message to say that there are errors.

    Where do I go from here?

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

    Question Netbeans 6.5

    Also when I tried the suggestion of

    Java Code:
     
    
              /*
          txtMnumber.setText(Double.toString(record.getMnumber()));
          txtRdate.setText(Double.toString(record.getRdate()));
          txtBmi.setText(Double.toString(record.getBmi()));
           */
          
          txtMnumber.setText(Double.toString(record.getMembership()));
          txtRdate.setText(Double.toString(record.getDate()));
          txtBmi.setText(Double.toString(record.getBmindex()));
    I have tried your suggestion but it flags errors, did you get errors?

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

    Question

    I then tried

    Java Code:
    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
                [COLOR="DarkGreen"]txtMnumber.setText(Double.toString(record.getMbrship()));
                txtRdate.setText(Double.toString(record.getDate()));
                txtBmi.setText(Double.toString(record.getBmindex()));[/COLOR]
                }

    This stopped the errors but then when I built and ran the app I got the following

    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: 1 second)
    Any suggestions, the main is fine there is no problem there, line 29 points to

    Java Code:
    File file = new File(new File(getClass().getResource("membership").getFile()),"mbrship.txt");
    I have the folder in the correct place yet I am now getting

    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: 1 second)
    How come I have no errors within the file but it still wont run, now I dont even get the gui

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

    Default

    The nullpointer could be because you don't have the file, mbrship.txt, in with your class files. This is the file that I was referring to earlier.

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

    Default

    This is all an expansion on a previous exercise that worked perfectly, I created the folder then when you ran the app and pressed new on the gui it created the text file.

    I shouldnt have to create the txt file manually. Even when I go back to the old exercise I did and delete the txt file then run the app and press new it works which tells me that I should be able to get this to work within this larger project.

    I have to say I am totally lost at the moment. Help!!!!!

    Thanks for your time

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

    Default

    If this were my project, I'd separate out the file input and output code into its own class, if only in the beginning just for debugging purposes, because right now your frmBmi class is getting a bit too big, too unwieldy to debug. Are you planning on using two files with this program, an input file and an output file?

    Also, why do you use this File constructor here:
    Java Code:
    File file = new File(new File(getClass().getResource("datafiles").getFile()), 
       "mship");
    that passes two String parameters, one obtained from the class's resources?
    Last edited by Fubarable; 03-15-2009 at 11:52 PM.

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

    Question

    This code was given to me from a tutor, as I say this was used in a previous exercise as attached, just a video rentals file where you list the secttion such as horror, film title, film duration and rental cost.

    The file attached is the original project that I built this one round.

    All the code in this file was given to me from a tutor.

    Can i ask what your recommendations are to replace the piece of code you are asking me about?
    Attached Files Attached Files

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

    Default netbeans

    what would u suggest in place of

    Java Code:
    File file = new File(new File(getClass().getResource("membership").getFile()),"mbrship.txt");

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

    Default

    You could create a File based on just a path String rather than base it on a resource.

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

    Default

    And what are the advantages to this, although I will have to ask for some idea of what you mean, i understand paths as in for a file location for example, are you meaning this? bearing in mind this has to be transferred to a cd and then onto another pc.

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

    Default

    Does this mean that we have exhausted all avenues in this forum?

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

    Default

    Have you worked on a class that does nothing but IO? I'm no IO pro but I'd do something like this:
    Java Code:
    import java.io.EOFException;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    
    public class TestFileIO
    {
      private static final String FILE_PATH = "src/bmiassessment3/dataFiles/objectdata3.txt";
      private File file = new File(FILE_PATH);
      private ObjectOutputStream out;
      private ObjectInputStream in;
    
      public void write()
      {
        try
        {
          out = new ObjectOutputStream(new FileOutputStream(file));
          for (int i = 0; i < 5; i++)
          {
            out.writeObject("Fubar " + i);
          }
        }
        catch (FileNotFoundException e)
        {
          e.printStackTrace();
        }
        catch (IOException e)
        {
          e.printStackTrace();
        }
        finally
        {
          if (out != null)
          {
            try
            {
              out.close();
            }
            catch (IOException e)
            {
              e.printStackTrace();
            }
          }
        }
      }
      
      public void read()
      {
        try
        {
          in = new ObjectInputStream(new FileInputStream(file));
          while (true)
          {
            String foo = in.readObject().toString();
            System.out.println(foo);
          }
        }
        catch (FileNotFoundException e)
        {
          e.printStackTrace();
        }
        catch (ClassNotFoundException e)
        {
          e.printStackTrace();
        }
        catch (EOFException e)
        {
          System.out.println("end of file");
        }
        catch (IOException e)
        {
          e.printStackTrace();
        }
        finally
        {
          if (in != null)
          {
            try
            {
              in.close();
            }
            catch (IOException e)
            {
              e.printStackTrace();
            }
          }
        }
      }
      
    
      public static void main(String[] args)
      {
        TestFileIO test = new TestFileIO();
        test.write();
        test.read();
      }
    }

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

    Thumbs up Netbeans 6.5

    Thanks, I will take a look at that but I have just put a very much smaller program together minus all the additional code.

    I cannot find the error in the code from before so I have started building the app again but this time logically thinking like you were hinting at before.

    I have cut all the chaff away and just got what I need so far then once thats working I will build it up.

    Just incase you are interested in the solution I have zipped and posted it.

    I have got to the add button so I need to get first and next working as well but so far so good

    Thanks a lot for your help and I am sure I wll be back!!

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

    Default

    Sorry I got an error as I was posting to say attachment wasnt attached, here we go hopefully.

    For some reason it wont let me post, maybe as I at college.....will try later when at home.

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

    Default

    Much luck!

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

    Question Netbeans 6.5

    :confused:

    I have attached the basic app with just 4 buttons and 3 text fields.

    The datafiles folder is in bmIndex/build/classes/bmindex/

    That was created manually however the text file is created by pressing new.

    I am at the stage now where I am putting the code in for the add button however at this moment I am getting a number of errors so have commented out the code.

    If anyone takes a look and works out the issue I would be grateful for a pointer in the right direction.

    Thanks
    Attached Files Attached Files

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

    Default

    I again had an error trying to create a new file with this program, but again it worked when I created a new file from a path string and not from a resource. Again I'm no expert on this, and I can't fully explain why this is. Perhaps someone else can explain better.

Page 3 of 3 FirstFirst 123

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
  •