<br clear="all">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/Test.java and org/freedesktop/dbus.test/TestRemoteInterface.java.<br>
But I get some exception when i run my program.<br><br>My code along with terminal output is as below :<br> <b><DBusInt.java></b><br><br>package pack1;<br>import org.freedesktop.dbus.DBusInterface;<br>
<br><br>//import <a href="http://org.apertium.Info">org.apertium.Info</a>; // The interface we use to access <a href="http://org.apertium.info/">org.apertium.info/</a><br><br>public interface DBusInt extends DBusInterface{<br>
public String myfun();<br>}<br><br> <b> <TestDBus.java><br></b><br><br>import org.freedesktop.DBus;<br>import org.freedesktop.dbus.exceptions.DBusException;<br>import org.freedesktop.dbus.*;<br>
import org.freedesktop.DBus.Peer;<br>import pack1.DBusInt;<br><br><br><br><br>//import <a href="http://org.apertium.Info">org.apertium.Info</a>; // The interface we use to access <a href="http://org.apertium.info/">org.apertium.info/</a><br>
<br><br>class testclass implements DBusInt<br>{<br> private DBusConnection conn;<br><br> public testclass(DBusConnection conn)<br> {<br> this.conn = conn;<br> }<br><br> /** Local classes MUST implement this to return false */<br>
public boolean isRemote() { return false; }<br><br> public String myfun()<br> {<br> System.out.println("Within myfun");<br> return "This is a response from myfun !!";<br>
}<br><br><br>}<br><br><br>public class TestDBus{<br><br> static DBusConnection serverconn = null;<br> static DBusConnection clientconn = null;<br><br> public static void main(String args[])throws DBusException{<br>
<br> serverconn = DBusConnection.getConnection(DBusConnection.SESSION);<br> clientconn = DBusConnection.getConnection(DBusConnection.SESSION);<br> <br> System.out.println("Registering Name");<br>
serverconn.requestBusName("foo.bar.Test");<br><br> System.out.println("Listening for Method Calls");<br> testclass tclass = new testclass(serverconn);<br><br> /** This exports an instance of the test class as the object /Test. */<br>
serverconn.exportObject("/Test", tclass);<br><br> System.out.println("Calling Method0/1 ");<br> /** This gets a remote object matching our bus name and exported object path. */<br>
<b> DBusInt tri = (DBusInt)clientconn.getPeerRemoteObject("foo.bar.Test", "/Test");</b><br> System.out.println("Got Remote Object: "+tri);<br><br> /** Call the remote object and get a response. */<br>
String rname = tri.myfun();<br> System.out.println("Got Remote Name: "+rname);<br> //String str=(DBusInt)clientconn.getPeerRemoteObject("foo.bar.Test", "/Test").myfun();<br>
}<br>}<br><br> <b><TERMINAL OUTPUT><br><br></b>Registering Name<br>Listening for Method Calls<br>Calling Method0/1<br>Exception in thread "main" java.lang.ClassCastException: $Proxy2 cannot be cast to pack1.DBusInt<br>
at TestDBus.main(TestDBus.java:57)<br><br><br><br>plz help me to fix this exception. I have bold marked the line in TestDBus.java which is causing exception.<br><br>Thanks in advance!!<br>-- <br>Regards,<br>Shiv Nath Kumar<br>