CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2000
    Location
    NJ
    Posts
    123

    strange problem (variables)

    Im putting together a small stupid little app using java and up to this point all has been well... However variable assignments in a particular method do not seem to work as I expect.
    While I hate to post so much code Im hoping that you might just take a look and try to explain why
    the assignments in openMenuItem_ActionPerformed method do not work... I used next_ActionPerformed method to test the assignment and the result is that the setText method is still performed after I have opened my file... likewise The Test object remains null....
    Is there an explanation for this????????


    public class Mainwin2 extends JFrame
    {
    private Test theTest = null;
    private boolean myFlag = false;
    int count =0; //master counter
    //many other variables initialized

    public void openMenuItem_ActionPerformed(java.awt.event.ActionEvent actionEvent)
    {
    utils.FileDlg dlg= new FileDlg("Open File");
    File MyFile = dlg.openFile();
    try
    {
    ObjectInputStream objectIn = new ObjectInputStream(
    new BufferedInputStream(
    new FileInputStream(MyFile)));
    theTest = (Test)objectIn.readObject();
    objectIn.close();
    myFlag =true; //SEEMS AS THOUGH BOTH ASSIGNMENTS DO NOT WORK
    //Yet no exceptions occur!!
    }
    catch(IOException e)
    {
    JOptionPane.showMessageDialog(this,"Ubable to openfile",
    "IOException",JOptionPane.ERROR_MESSAGE);
    }
    catch(ClassNotFoundException e)
    {
    JOptionPane.showMessageDialog(this,"Ubable to open file",
    "ClassNotFoundException",JOptionPane.ERROR_MESSAGE);
    }
    }




    thanks for the time and well hopefully for some kind of explanation....
    J.Prisco


    52901368

  2. #2
    Join Date
    Apr 2000
    Location
    NJ
    Posts
    123

    complete code

    left out some code

    public class Mainwin2 extends JFrame
    {
    private Test theTest = null;
    private boolean myFlag = false;
    int count =0; //master counter
    //many other variables initialized

    public void openMenuItem_ActionPerformed(java.awt.event.ActionEvent actionEvent)
    {
    utils.FileDlg dlg= new FileDlg("Open File");
    File MyFile = dlg.openFile();
    try
    {
    ObjectInputStream objectIn = new ObjectInputStream(
    new BufferedInputStream(
    new FileInputStream(MyFile)));
    theTest = (Test)objectIn.readObject();
    objectIn.close();
    myFlag =true; //SEEMS AS THOUGH BOTH ASSIGNMENTS DO NOT WORK
    //Yet no exceptions occur!!
    }
    catch(IOException e)
    {
    JOptionPane.showMessageDialog(this,"Ubable to openfile",
    "IOException",JOptionPane.ERROR_MESSAGE);
    }
    catch(ClassNotFoundException e)
    {
    JOptionPane.showMessageDialog(this,"Ubable to open file",
    "ClassNotFoundException",JOptionPane.ERROR_MESSAGE);
    }
    }
    return;
    }
    public void next_ActionPerformed(java.awt.event.ActionEvent actionEvent)
    {

    if(myFlag==false)
    ivjquestion.setText("replaced fowl language just for you");

    return;
    }






    52901368

  3. #3
    Join Date
    Mar 2000
    Location
    Dublin, Ireland
    Posts
    124

    Re: complete code

    J. Prisco,

    I'm not too sure what the problem is but I take it that the myFlag boolean is not being set to true.

    If this is the case, then try setting myFlag to true before the try block, then set it to false within the catch blocks.

    It's a quick fix but I haven't time to compile your code...

    Hope this helps.

    Regards,

    dogBear

    PS Please Rate this Response!!!!

  4. #4
    Join Date
    Apr 2000
    Location
    NJ
    Posts
    123

    Re: complete code

    Tht was indeed a quick fix for the myFlag variable which is important to the app however the more important part of the function is reading in an object from a file.... After opening and reading in the assignment to "theTest" still does not take.. referncing it in similar fassion as I did with "myFlag" indicates it remains in a null state..
    Im thinking maybe i should be using the "throws clause instead of try catch but Im not really sure what to do... I appreciate the help on this and if you can help me further Id greatly appreciate it

    thanks for the time,
    J.Prisco

    52901368

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured