Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

instantiating new Object in Exception catch block not resolving .....

Status
Not open for further replies.

asiavoices

Programmer
Sep 20, 2001
90
CA
Hello all,

This has me stump....

I have an exception that I want caught in a catch block and when it's caught, it will call my dialog window (works fine except in this situation).

The error message I got was :

cannot resolve symbol...

new MsgDialog(this, "Error!", "My error message here");
^


Here's a bit of my code:

try
{
int numID = (Integer.parseInt(idField.getText()));
}

catch (NumberFormatException ex)
{
new MsgDialog(this, "Error!", "My error message here");
}


I don't get it [sadeyes] .... Shouldn't it just do a new MsgDialog?

How come it can't resolve the "new" symbol?

Any help is greatly welcomed.

thanks,

Chris




 
hi

i dunno whats wrong with a 'new' in catch, but i can suggest something. i guess u r extending Dialog class to form that MsgDialog. dont call the show() method in the constructor. instantiate MsgDialog elsewhere, then call its show method alone in the catch block.

luv
Karthik.
LOL A ship is safe in the harbour, but that's not what it is meant for!!! LOL
 


I found something interesting.....

This code is an extended from a Dialog class and my "new" object is also from a Dialog class.

It would seem that it doesn't want to instantiate a new dialog class from another Dialog class. I'm sure this is not true.

Here's some more of my code for clarification:

-------------
Form.java
-------------

public class Form extends Dialog
implements ActionListener
{

......

try
{
int numID = (Integer.parseInt(idField.getText()));
}

catch (NumberFormatException ex)
{
new MsgDialog(this, "Error!", "My error message here");
}

.......
} // end of Form.java




------------------
MsgDialog.java
------------------

public class MsgDialog extends Dialog
implements ActionListener
{
........

}


What could it be?

Chris

 


Hello vkarthik,

I do not have a show() method in my constructor.


Here's a bit more....


public class MsgDialog extends Dialog
implements ActionListener
{

public MsgDialog(Frame parent, String title, String textmsg)
{
super(parent, title, true);
this.msgbody = textmsg.toUpperCase().trim();
this.setLayout(new BorderLayout());
this.setResizable(false);
this.setBounds(200, 150, 300, 275);
....
this.setVisible(true);
}

......

} // end of MsgDialog class


How would you approach it?

Thanks,

Chris
 
I think you have to create a MsgDialog object first, like this:

MsgDialog myDialog = new MsgDialog(this, "Error!", "My error message here");
 
Yes you must assigned the newly created object to reference if you ever plan on using it. Otherwise it will be created and immediately be out of scope.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top