1

I am working in Android Studio and trying to compile some existing code, but I get an "incompatible type" (object required) error for variable BluetoothDevice at this line, though I have the import line at the top of the code:

import android.bluetooth.BluetoothDevice;

/* other code */

for(BluetoothDevice bt : pairedDevices) 

Here is the function with the line of interest:

public void pairedDevicesList() {
    pairedDevices = myBluetooth.getBondedDevices();
    ArrayList list = new ArrayList();

    if (pairedDevices.size() > 0) {
        for(BluetoothDevice bt : pairedDevices) {
            list.add(bt.getName() + "\n" + bt.getAddress()); //Get the device's name and the address}
        }
    } else {
        Toast.makeText(getApplicationContext(), "No Paired Bluetooth Devices Found.", Toast.LENGTH_LONG).show();
    }

    final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, list);
    devicelist.setAdapter(adapter);
    devicelist.setOnItemClickListener(myListClickListener); //Method called when the device from the list is clicked
}

Any ideas? Thanks

Binkan Salaryman
  • 3,008
  • 1
  • 17
  • 29
wrfstudios
  • 19
  • 2
  • 1
    I'm pretty sure `pairedDevices` is a raw type like your `ArrayList list = new ArrayList()`. So ... read why they shouldn't be that. – Tom Sep 30 '16 at 20:00
  • Can you include the declaration for `pairedDevices`? – Joe C Sep 30 '16 at 20:07
  • Thanks everyone... it turns out I needed these two lines prior to that "for" statement... BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); Set pairedDevices = bluetoothAdapter.getBondedDevices(); – wrfstudios Sep 30 '16 at 20:29

0 Answers0