Click to See Complete Forum and Search --> : strange problem (variables)


Jprisco
September 19th, 2000, 01:06 AM
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

Jprisco
September 19th, 2000, 01:10 AM
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

dogbear
September 19th, 2000, 03:42 AM
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!!!!

Jprisco
September 19th, 2000, 11:56 AM
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