<br><div class="gmail_quote"><div><div></div><div class="h5"><br>Hi all,<br><div class="gmail_quote"><br>I am  newbie in DBus programming using java. I am trying to call a method &quot;myfun&quot; on an object of class &quot;Demo&quot; in a simple java program (TestDBus.java) from another java program (TestDBus1.java) using DBus Connection. I am able to connecct both these applications to DBus but my code is not able to call method &quot;myfun&quot; and I got some exception. My code and run time exception are as below :<br>
                                     &lt; <b>Demo.java </b>&gt;<br><br>package pack;<br>import org.freedesktop.DBus;<br>import org.freedesktop.dbus.DBusConnection;<br>

import org.freedesktop.dbus.exceptions.DBusException;<br>import org.freedesktop.dbus.DBusInterface;<br><br>interface TestDBusInt extends DBusInterface{<br>public void myfun();<br>}<br><br>public class Demo implements TestDBusInt{<br>


    public Demo(){}<br>    public boolean isRemote(){return false;}<br>    public void myfun(){<br>        System.out.println(&quot;Within myfun of Demo class within TestDBus.class&quot;);<br>    }    <br>}<br><br><br>                                      &lt;<b>TestDBus.java</b> &gt;<br>


<br>import org.freedesktop.DBus;<br>import org.freedesktop.dbus.exceptions.DBusException;<br>import org.freedesktop.dbus.*;<br>import pack.Demo;<br><br>public class TestDBus{<br><br>        public static void main(String[] args) throws org.freedesktop.dbus.exceptions.DBusException {<br>


                DBusConnection bus = null;<br><br>               // Getting the Bus Connection.<br><br>        System.out.println(&quot;Connecting Bus........&quot;);<br><br>                bus = DBusConnection.getConnection(DBusConnection.SESSION);<br>


<br>                System.out.println(&quot;Bus Connection Established.&quot;);<br><br>        //Getting Unique name of this connection.<br>        String conName=bus.getUniqueName();<br>        System.out.println(&quot;Unique Name of this Bus Connection =&gt; &quot;+conName);<br>


        <br>        <br>        //Requesting Bus Name.<br>        bus.requestBusName(&quot;My.FirstBus&quot;);<br><br>        <br>        //Getting the names owned by this connection.<br>        System.out.println(&quot;Names owned by this Bus Connection are =&gt;&quot;);<br>


        String []bnames1=bus.getNames();<br>        for(int i=0;i&lt;bnames1.length;i++)<br>            System.out.println(bnames1[i]);<br>        <br><br>        //exporting the Demo class object on the path “/Test”<br>

        <br>
      <b>  DBusInterface db1=new Demo();<br>        bus.exportObject(&quot;/Test&quot;, db1);</b><br>                   <br>        while(true){}<br>       <br>        }    <br>}<br><br clear="all">                                         &lt;<b>TestDBus1.java</b>&gt;<br>


<br>import org.freedesktop.DBus;<br>import org.freedesktop.dbus.*;<br>import java.lang.reflect.*;<br>import org.freedesktop.DBus.Introspectable;<br>import org.freedesktop.*;<br>import pack.Demo;<br><br><br>public class TestDBus1 {<br>


    <br>        public static void main(String[] args) throws org.freedesktop.dbus.exceptions.DBusException {<br>        DBusConnection bus1 = null;<br>        DBusConnection bus2=null;<br>                <br>                System.out.println(&quot;Establishing Bus Connection.......&quot;);<br>


<br>                bus1 = DBusConnection.getConnection(DBusConnection.SESSION);<br>              <br>                 System.out.println(&quot;Bus Connection Established.&quot;);<br><br>        //Getting Unique name of this connection.<br>


        String conName1=bus1.getUniqueName();<br>        System.out.println(&quot;Unique Name of this Bus Connection =&gt; &quot;+conName1);<br>        <br><br>        // Getting and Displaying Introspection data on Remote Object.<br>


       <b> Introspectable intro = (Introspectable) bus1.getRemoteObject(<br>                              &quot;My.FirstBus&quot;, &quot;/Test&quot;,<br>                               Introspectable.class);<br><br>        String data = intro.Introspect();</b><br>


<br>        <br><br>        <br>        //System.out.println(db.myfun());<br><br><br>        System.out.println(&quot;&lt;--------------------------- Introspection Data Start -----------------------------------&gt;&quot;);<br>


        System.out.println(data);<br>        System.out.println(&quot;&lt;--------------------------- Introspection Data End   -----------------------------------&gt;&quot;);<br>        <br><br>        //Getting the remote object and calling a method of that object.<br>

 
<b>DBusInterface db =bus1.getPeerRemoteObject(&quot;</b><b>My.FirstBus&quot;,&quot;/Test&quot;);<br>        DBusAsyncReply&lt;Boolean&gt; stuffreply =bus1.callMethodAsync(db,&quot;</b><b>myfun&quot;);</b><br>        <br>

<br>         while(true){}<br>
                 <br>        }<br>}<br><br><br><br><br>

<br>&lt;<b>Console Output on running TestDBus.java</b>&gt;<br><br><br>Connecting Bus........<br>Bus Connection Established.<br>Unique Name of this Bus Connection =&gt; :1.39<br>

Names owned by this Bus Connection are =&gt;<br>:1.39<br>My.FirstBus<br><br><br><br>&lt; <b>Console Output
on running TestDBus1.java</b>&gt;<br><br>Establishing Bus Connection.......<br>Bus Connection Established.<br>Unique Name of this Bus Connection =&gt; :1.40<br>&lt;--------------------------- Introspection Data Start -----------------------------------&gt;<br>


&lt;!DOCTYPE node PUBLIC &quot;-//freedesktop//DTD D-BUS Object Introspection 1.0//EN&quot; &quot;<a href="http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" target="_blank">http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd</a>&quot;&gt;<br>


&lt;node name=&quot;/Test&quot;&gt;<br> &lt;interface name=&quot;pack.TestDBusInt&quot;&gt;<br>  &lt;method name=&quot;myfun&quot; &gt;<br>  &lt;/method&gt;<br> &lt;/interface&gt;<br> &lt;interface name=&quot;org.freedesktop.DBus.Introspectable&quot;&gt;<br>


  &lt;method name=&quot;Introspect&quot;&gt;<br>   &lt;arg type=&quot;s&quot; direction=&quot;out&quot;/&gt;<br>  &lt;/method&gt;<br> &lt;/interface&gt;<br> &lt;interface name=&quot;org.freedesktop.DBus.Peer&quot;&gt;<br>


  &lt;method name=&quot;Ping&quot;&gt;<br>  &lt;/method&gt;<br> &lt;/interface&gt;<br>&lt;/node&gt;<br>&lt;--------------------------- Introspection Data End   -----------------------------------&gt;<br>Exception in thread &quot;main&quot; org.freedesktop.dbus.exceptions.DBusExecutionException: $Proxy2.myfun()<br>


        at org.freedesktop.dbus.AbstractConnection.callMethodAsync(AbstractConnection.java:683)<br>        at TestDBus1.main(TestDBus1.java:48)<br>&lt;<b>End of Console Output</b>&gt;<br>

<br>I am not sure, if I am missing something obvious here and would  appreciate any advice on this. Plz, help me if I am going wrong in some way. Plz suggest me what to do to fix such exception and call the method as I want. <br>
Am i doing anything wrong in specifying and using object path and/or bus name?<br>

Waiting for your reply. <br><br>Thanks in Advance !!<br><br></div>-- <br>Regards,<br>Shiv Nath Kumar<br>
</div></div></div><br><br clear="all"><br>-- <br>Regards,<br>Shiv Nath Kumar<br>