Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2005

Tip: Looking for answers? Try searching our database.

Bluetooth, send msg from soft key evet.

Thread view: 
Boki - 22 Mar 2005 00:36 GMT
Hi All,
          I try a bluelet demo, I change some code here, I want to move
these codes of run()
========================================================
       out.writeUTF( "Boki Back Msg" );
       out.flush();
========================================================

to a soft key event, but it never work ( exception error is 0 / null )

public void commandAction(Command c, Displayable s) {
========================================================
       out.writeUTF( "Boki Back Msg" );
       out.flush();
========================================================
}

My original thread:

=============================================
 public void run()
 {

   StreamConnection c = null;
   try
   {
       localDevice = LocalDevice.getLocalDevice(); // obtain reference to
singleton
     localDevice.setDiscoverable(DiscoveryAgent.GIAC); // set Discover mode
to LIAC

String uuidString = "102030405060708090A0B0C0D0E0F010";
UUID uuid = new UUID(uuidString, false);

            String url = "btspp://localhost:" + uuid.toString()
+";name=Boki_SPP";

         server =  (StreamConnectionNotifier)Connector.open( url );
   localDevice.setDiscoverable(DiscoveryAgent.GIAC);

          ServiceRecord rec = localDevice.getRecord( server );

         rec.setAttributeValue( 0x0008, new DataElement(
DataElement.U_INT_1, 0xFF ) );

   } catch (Exception e)
   {

    System.out.println("try1 fail"+e.getMessage());
      System.out.println(e);
   }

   while( !done)
   {
     try {
                System.out.println("try2");

        c = server.acceptAndOpen();
          RemoteDevice rdev = RemoteDevice.getRemoteDevice( c );

          DataInputStream in = c.openDataInputStream();
       String s = in.readUTF();

       DataOutputStream out = c.openDataOutputStream();
========================================================
       out.writeUTF( "Boki Back Msg" );
       out.flush();
========================================================
       // close current connection, wait for the next one
     // c.close();

     } catch (Exception e)
     {
        System.out.println("try2 fail");
     }

   } // while

 }
Tor Iver Wilhelmsen - 22 Mar 2005 15:08 GMT
>  public void commandAction(Command c, Displayable s) {
> ========================================================
>         out.writeUTF( "Boki Back Msg" );
>         out.flush();
> ========================================================
> }

How do you obtain "out" in this case? Do you use the samme Connection
calls you do in the posted run() method?
boki - 23 Mar 2005 12:35 GMT
> >  public void commandAction(Command c, Displayable s) {
> > ========================================================
[quoted text clipped - 5 lines]
> How do you obtain "out" in this case? Do you use the samme Connection
> calls you do in the posted run() method?

Yes, I use the same conector.open
Darryl Pierce - 24 Mar 2005 14:12 GMT
> Hi All,
>            I try a bluelet demo, I change some code here, I want to move
[quoted text clipped - 5 lines]
>
> to a soft key event, but it never work ( exception error is 0 / null )

Right there's your answer, but you didn't write out the actual error so
I have to assume it. You're getting a null pointer exception. Think
about it for a minute: what could be null in the following code block?

>  public void commandAction(Command c, Displayable s) {
> ========================================================
>         out.writeUTF( "Boki Back Msg" );
>         out.flush();
> ========================================================
> }

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard

Boki - 24 Mar 2005 15:20 GMT
Yes, it is a null pointer exception, you are right.

but, what could I do...

the variables define in try {} will be deleted when process exit.

Should I keep the try { c=connector.open(XXX) .........} live?

Best regards,
Boki.

"Darryl Pierce" <mcpierce@gmail.com>
???????:2%y0e.51707$c72.25105@bignews3.bellsouth.net...
>> Hi All,
>>            I try a bluelet demo, I change some code here, I want to move
[quoted text clipped - 16 lines]
>> ========================================================
>> }
Darryl Pierce - 26 Mar 2005 05:06 GMT
> Yes, it is a null pointer exception, you are right.
>
[quoted text clipped - 3 lines]
>
> Should I keep the try { c=connector.open(XXX) .........} live?

That depends on your application's needs. If the connection needs to be
used for more than a single method invokation then you need to have a
reference to it somewhere so it can be accessed from those other locations.

Signature

Darryl L. Pierce <mcpierce@gmail.com>
Visit my homepage: http://mcpierce.multiply.com
"By doubting we come to inquiry, through inquiry truth." - Peter Abelard



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.