Associate
- Joined
- 24 Jun 2007
- Posts
- 1,869
- Location
- Landan.
Edit: Posted full source below
Evening all,
I'm creating an app that makes use of a JavaBean for some separate functions. However, I have a problem whereby the JavaBean's main constructor can throw a ClassNotFoundException, but when I come to use it in my main app I want to create and initialise outside (and above) main so that it can be used throughout the app.
Perhaps it'd be easier to show it in code:
The JavaBean
The main app:
I've underlined what Eclipse underlines, and gives the error:
So - how do I somehow work throws ClassNotFoundException into the declaration and creation of the OrderHandling class?
Any help or pointers would be greatly received
Thanks!
Evening all,
I'm creating an app that makes use of a JavaBean for some separate functions. However, I have a problem whereby the JavaBean's main constructor can throw a ClassNotFoundException, but when I come to use it in my main app I want to create and initialise outside (and above) main so that it can be used throughout the app.
Perhaps it'd be easier to show it in code:
The JavaBean
Code:
public class OrderHandling
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
public OrderHandling() throws ClassNotFoundException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfEx)
{
throw new ClassNotFoundException(
"Unable to locate JDBC driver!");
}
}
//Functions follow...
Code:
public class MenuSystem {
private static int option;
public OrderHandling calcOrder = new [U]OrderHandling[/U]();
public static void main (String[] args)
{
<-- Do stuff -->
}
So I get that, the bean throws the exception, and my app doesn't know what to do with it.Default constructor cannot handle exception type ClassNotFoundException thrown by implicit super constructor. Must define an explicit constructor
So - how do I somehow work throws ClassNotFoundException into the declaration and creation of the OrderHandling class?

Any help or pointers would be greatly received

Thanks!
Last edited: