Your implementation class needs to be declared in the following manner:

public class InterImplementation implements SampleInterface
{
        //method implementations go here...     
}

This defines a concrete class called InterImplementation that implements the
SampleInterface interface.  To call methods on the interface it is now
necessary to create a reference that is the type of the interface and then
point it to an instance of the implementation class
e.g.

SampleInterface samp = new InterImplementation();

this is similar to doing:

InterImplementation newObject = new InterImplementation();
SampleInterface samp = newObject;

You must create an instance of the implementation class and then point your
interface to it.  You may then reference the object through this interface.

It is important to think of objects (or instances) and references.  You can
think of an object as a helium balloon.  References are the string that you
tie to it and hold it by.  A balloon may have more than one string tied to
it.  In your example code you had a string but no balloon.  The balloon is
the important part the string is just how you refer to it.  

In this analogy once the string (reference) is connected to the balloon
(object), using the code above, you may then call methods on it.
e.g.

samp.getData();

Hope this helps.


-----Original Message-----
From: Ramesh Nuthalapati [mailto:[EMAIL PROTECTED]]
Sent: 16 October 2001 13:10
To: BOWMAN,James
Subject: (ROSE) Interface - subsystem



Hi James

Thanks for your suggestion. I agree what you are saying but i am asking
about the interface, not about the class. My problem is how to access a
class which is having implementation of my interface methods. So when i
invoke my interface methods it should go and execute methods which are there
in the subsystem.

Suppose that a class named interimplementation(subsystem) has the methods
implemented in it. so in a class named callingclass  i am calling the
interface methods there i am getting the null pointer exception.

Everything is kept in a package. when i call interface methods, how
interface will know that there is a implementation for it in the class
called interimplementation and how the methods were called. 

Please help me in this matter.

Hope you got my point.

Thanks
Ramesh Nuthalapati.


On Tue, 16 Oct 2001 BOWMAN, James wrote :
> 
> You are getting a null pointer exception because you 
> have not instantiated
> the object yet.  An object must be instantiated before 
> it can be used.  This
> is very fundamental and you should really spend some 
> time getting to grips
> with this.
> 
> The first line of your code declares a reference called 
> samp of type
> InterfaceSample.  This is fine.  It then sets the 
> reference to point at
> null.  This means you have a reference but no object 
> upon which to call
> methods.  You must set the reference equal to the 
> address of an object
> before you can use it rather than null.  e.g.  Sample 
> samp = new Sample();
> 
> In your case this will not work however because you are 
> using an interface.
> An interface cannot be instantiated i.e. you cannot 
> create an object of that
> type by using new.  If you want the reference to be the 
> type of the
> interface, you must make it point to an object that 
> implements that
> interface
> 
> e.g.
> 
> SampleInterface samp = new SampleImplementation();
> samp.getData();
> 
> The class SampleImplementation must be provide 
> implementations for all of
> the methods declared in SampleInterface and it must be 
> declared using the
> following:
> 
> public class SampleImplementation implements 
> SampleInterface
> 
> I hope this helps
> 
> 
> 
> -----Original Message-----
> From: Ramesh Nuthalapati [mailto:[EMAIL PROTECTED]]
> Sent: 16 October 2001 11:06
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: (ROSE) Interface - subsystem
> 
> 
> 
> 
> Hi all
> 
> I have an interface. i have implemented this interface 
> in a sub system. so
> my class should access the interface methods which are 
> implemented in the
> subsystem. when i am trying to call methods 
> 
> InterfaceSample samp=null;
> samp.getData();
> 
> when i used this in my class it says "NULL" and is 
> throwing exception.
> 
> Please help me in this issue. how do i call methods 
> which are implemeted in
> my subsystem through interface.
> 
> everything i have kept in a package.
> 
> 
> Thanks in advance
> Ramesh Nuthalapati. 
> 
> ********************************************************-
> ****************
> * Rose Forum is a public venue for ideas and 
> discussions.
> * For technical support, visit 
> http://www.rational.com/support
> *
> * Admin.Subscription Requests: [EMAIL PROTECTED]
> * Archive of messages:
> http://www.rational.com/support/usergroups/rose/rose_for-
> um.jsp
> * Other Requests: [EMAIL PROTECTED]
> *
> * To unsubscribe from the list, please send email
> *
> * To: [EMAIL PROTECTED]
> * Subject:<BLANK>
> * Body: unsubscribe rose_forum
> *
> ********************************************************-
> *****************
> 
> 
> ________________________________________________________-
> ___________________
> This email is confidential and intended solely for the 
> use of the 
> individual to whom it is addressed. Any views or 
> opinions presented are 
> solely those of the author and do not necessarily 
> represent those of 
> SchlumbergerSema. 
> If you are not the intended recipient, be advised that 
> you have received this
> email in error and that any use, dissemination, 
> forwarding, printing, or 
> copying of this email is strictly prohibited.
> 
> If you have received this email in error please notify 
> the SchlumbergerSema Helpdesk by telephone on +44 (0) 
> 121 627 5600.
> ________________________________________________________-
> ___________________
> 
> ********************************************************-
> ****************
> * Rose Forum is a public venue for ideas and 
> discussions.
> * For technical support, visit 
> http://www.rational.com/support
> *
> * Admin.Subscription Requests: [EMAIL PROTECTED]
> * Archive of messages: http://www.rational.com/support/u-
> sergroups/rose/rose_forum.jsp
> * Other Requests: [EMAIL PROTECTED]
> *
> * To unsubscribe from the list, please send email
> *
> * To: [EMAIL PROTECTED]
> * Subject:<BLANK>
> * Body: unsubscribe rose_forum
> *
> ********************************************************-
> *****************
> 
 


___________________________________________________________________________
This email is confidential and intended solely for the use of the 
individual to whom it is addressed. Any views or opinions presented are 
solely those of the author and do not necessarily represent those of 
SchlumbergerSema. 
If you are not the intended recipient, be advised that you have received this
email in error and that any use, dissemination, forwarding, printing, or 
copying of this email is strictly prohibited.

If you have received this email in error please notify the SchlumbergerSema Helpdesk 
by telephone on +44 (0) 121 627 5600.
___________________________________________________________________________

************************************************************************
* Rose Forum is a public venue for ideas and discussions.
* For technical support, visit http://www.rational.com/support
*
* Admin.Subscription Requests: [EMAIL PROTECTED]
* Archive of messages: http://www.rational.com/support/usergroups/rose/rose_forum.jsp
* Other Requests: [EMAIL PROTECTED]
*
* To unsubscribe from the list, please send email
*
* To: [EMAIL PROTECTED]
* Subject:<BLANK>
* Body: unsubscribe rose_forum
*
*************************************************************************

Reply via email to