override problem

D

Daniel

I want to implement rmi and get this error

test/PatientGui.java [151:1] getEnToonData() in test.PatientGui cannot
override getEnToonData() in test.ViewModel; overridden method does not throw
java.rmi.RemoteException

Public class PatientGui
void getEnToonData() throws java.rmi.RemoteException
{
:
}

Public Class ViewModel

void getEnToonData()
{
System.out.println("Moet nog gemaakt worden in de sub-class");
}

If i remove the throws java.rmi.RemoteException, the compiler tells me it
should be thrown.

How can i solve this?
Thanks

Daniel
 
P

Peter J. Grey

Daniel said:
I want to implement rmi and get this error

test/PatientGui.java [151:1] getEnToonData() in test.PatientGui cannot
override getEnToonData() in test.ViewModel; overridden method does not throw
java.rmi.RemoteException

Public class PatientGui
void getEnToonData() throws java.rmi.RemoteException
{
:
}

Public Class ViewModel

void getEnToonData()
{
System.out.println("Moet nog gemaakt worden in de sub-class");
}

If i remove the throws java.rmi.RemoteException, the compiler tells me it
should be thrown.

I'm guessing that these classes implement java.rmi.Remote, either
explicitly or in their base classes. RMI requires (if I remember right)
the throws java.rmi.RemoteException for a class implementing
java.rmi.Remote, so if it's in the base class, it will have to be in the
descendant class.

This is a little funny, because the usual rule is that if an exception
is thrown in the base class method, the subclass method can throw the
same exception, or any smaller set of exceptions (meaning a more
specific exception type), and this can include having no throws clause
at all in the subclass method.

Peter G
 
D

Daniel

Hello, yes the base class implements UnicastRemoteObject and the Interface
extends Remote,

But i dont know how to solve this, what should i change?
Peter J. Grey said:
Daniel said:
I want to implement rmi and get this error

test/PatientGui.java [151:1] getEnToonData() in test.PatientGui cannot
override getEnToonData() in test.ViewModel; overridden method does not
throw
java.rmi.RemoteException

Public class PatientGui
void getEnToonData() throws java.rmi.RemoteException
{
:
}

Public Class ViewModel

void getEnToonData()
{
System.out.println("Moet nog gemaakt worden in de sub-class");
}

If i remove the throws java.rmi.RemoteException, the compiler tells me it
should be thrown.

I'm guessing that these classes implement java.rmi.Remote, either
explicitly or in their base classes. RMI requires (if I remember right)
the throws java.rmi.RemoteException for a class implementing
java.rmi.Remote, so if it's in the base class, it will have to be in the
descendant class.

This is a little funny, because the usual rule is that if an exception is
thrown in the base class method, the subclass method can throw the same
exception, or any smaller set of exceptions (meaning a more specific
exception type), and this can include having no throws clause at all in
the subclass method.

Peter G
 
P

Peter J. Grey

Daniel said:
Hello, yes the base class implements UnicastRemoteObject and the Interface
extends Remote,
But i dont know how to solve this, what should i change?

It looks like you need
void getEnToonData() throw java.rmi.RemoteException
because if it's for RMI, then you would expect that a
java.rmi.RemoteException could come up.

Peter G
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,267
Latest member
WaylonCogb

Latest Threads

Top