Java DBus : Exception in calling remote object method

Shiv Nath Kumar shivnath27 at
Sun Mar 7 21:04:25 PST 2010

I want to call a remote object method using DBus. I developed some  code for
that taking some help from the source code of
org/freedesktop/dbus/test/ and
But I get some exception when i run my program.

My code along with terminal output is as below :

package pack1;
import org.freedesktop.dbus.DBusInterface;

//import org.apertium.Info; // The interface we use to access

public interface DBusInt extends DBusInterface{
public String myfun();

                                                      * <>

import org.freedesktop.DBus;
import org.freedesktop.dbus.exceptions.DBusException;
import org.freedesktop.dbus.*;
import org.freedesktop.DBus.Peer;
import pack1.DBusInt;

//import org.apertium.Info; // The interface we use to access

class testclass implements DBusInt
       private DBusConnection conn;

       public testclass(DBusConnection conn)
              this.conn = conn;

     /** Local classes MUST implement this to return false */
       public boolean isRemote() { return false; }

    public String myfun()
        System.out.println("Within myfun");
             return "This is a response from myfun !!";


public class TestDBus{

    static DBusConnection serverconn = null;
       static DBusConnection clientconn = null;

    public static void main(String args[])throws DBusException{

            serverconn =
              clientconn =

              System.out.println("Registering Name");

        System.out.println("Listening for Method Calls");
              testclass tclass = new testclass(serverconn);

              /** This exports an instance of the test class as the object
/Test. */
              serverconn.exportObject("/Test", tclass);

         System.out.println("Calling Method0/1 ");
              /** This gets a remote object matching our bus name and
exported object path. */
             * DBusInt tri =
(DBusInt)clientconn.getPeerRemoteObject("", "/Test");*
              System.out.println("Got Remote Object: "+tri);

              /** Call the remote object and get a response. */
              String rname = tri.myfun();
              System.out.println("Got Remote Name: "+rname);
        //String str=(DBusInt)clientconn.getPeerRemoteObject("",

                                                         *<TERMINAL OUTPUT>

*Registering Name
Listening for Method Calls
Calling Method0/1
Exception in thread "main" java.lang.ClassCastException: $Proxy2 cannot be
cast to pack1.DBusInt
        at TestDBus.main(

plz help me to fix this exception. I have bold marked the line in which is causing exception.

Thanks in advance!!
Shiv Nath Kumar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the dbus mailing list