Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5935371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:14:41+00:00 2026-05-22T15:14:41+00:00

I am having problems with my remote device discovery code for bluetooth scanning. It

  • 0

I am having problems with my remote device discovery code for bluetooth scanning.
It scans, and prints the MAC addresses if i uncomment the “system.out.print(devicesDiscovered);

But i want to be able to extract each MAC address from the Vector and place it in a String.

I have two differant FOR loops to do this, but neither of them seem to be executing.

Code:

import java.io.IOException;
import java.util.List;
import java.util.Vector;
import javax.bluetooth.*;

public class BluetoothDeviceDiscovery {

    public static final Vector/*<RemoteDevice>*/ devicesDiscovered = new Vector();

    public static void main() throws IOException, InterruptedException {

        final Object inquiryCompletedEvent = new Object();

        devicesDiscovered.clear();

        final DiscoveryListener listener = new DiscoveryListener() {

            public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {              
                devicesDiscovered.addElement(btDevice);

                //
                String testingAgain = devicesDiscovered.toString();
                System.out.println("What?? : " + testingAgain);

                /*
                * As far as i know, the following two FOR loops do the same thing
                * But both of them are not being executed...
                */

                //Its not executing this...
                for(int i=0; i< devicesDiscovered.size(); i++) {
                    System.out.println("test if this gets output");
                    String test = (String) devicesDiscovered.elementAt(i);
                    System.out.println("Test: " + test);
                }                
                //Its not executing this....
                for(int i=0; i> ((List) btDevice).size(); i++){
                    System.out.println("test if this gets output 1");
                    String testing = (String) devicesDiscovered.toString();
                    System.out.print("Test1: " + testing);
                }
                //Prints the MAC addresses [macaddress, macaddress, macaddress, etc]
               // System.out.println(devicesDiscovered);



                /*
                 * Now need to extract each macaddress from devicesDiscovered
                 * and convert from a Vector to a String
                 */
            }

            public void inquiryCompleted(int discType) {
                System.out.println("Device Inquiry completed!");
                synchronized(inquiryCompletedEvent){
                    inquiryCompletedEvent.notifyAll();
                }
            }

            public void serviceSearchCompleted(int transID, int respCode) {
            }

            public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
            }
        };

        synchronized(inquiryCompletedEvent) {
            boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, listener);
            if (started) {
                System.out.println("wait for device inquiry to complete...");
                inquiryCompletedEvent.wait();
                System.out.println(devicesDiscovered.size() +  " device(s) found");
            }
        }

    }
}

Can anyone spot any reason(s) as to why these two for loops are not working?

Thanks a lot
– Ryan

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:14:42+00:00Added an answer on May 22, 2026 at 3:14 pm

    The execution of your code in my machine is the following:

    BlueCove version 2.1.0 on bluez

    wait for device inquiry to complete…

    What?? : […]

    test if this gets output

    Test: …

    Device Inquiry completed!

    1 device(s) found

    BlueCove stack shutdown completed

    With the following for loop:

    for(int i=0; i< devicesDiscovered.size(); i++) 
    {
        System.out.println("test if this gets output");
        String test = (String) devicesDiscovered.elementAt(i).toString();
        System.out.println("Test: " + test);
    }
    

    I’ve noticed that you were testing which one of the for loops was generating the output that you wanted. I can say that the above one works but the second generates an exception. You are trying to cast a RemoteDevice object to a List and iterate through it (for(int i=0; i < ((List) btDevice).size(); i++)). That’s the reason for not working and therefore the exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having big problems in fetching exception details from Remote EJBs... I have
I'm having some problems figuring out a solution to this problem. I want to
I'm having problems with Iterator.remove() called on a HashSet. I've a Set of time
I'm having a problem getting access to a database which lives on a remote
Im having problems displaying records to my view when passing viewdata to a user
Im having problems building a query with the linq to sql data query expression
I have recently started having problems with TortoiseCVS, or more specifically with plink, the
I'm having problems using textures that are larger than the OpenGL window or the
I'm having problems deciding on what is the best way is to handle and
I am having problems getting text within a table to appear centered in IE.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.