Java:“INCOMPATIBLE TYPE”错误

时间:2016-09-30 19:28:12

标签: java android bluetooth

我在Android Studio中工作并尝试编译一些现有代码,但我得到变量BluetoothDevice的“不兼容类型”(需要对象)错误 在这一行,虽然我在代码的顶部有导入行:

import android.bluetooth.BluetoothDevice;

/* other code */

for(BluetoothDevice bt : pairedDevices) 

以下是感兴趣的行的功能:

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
}

有什么想法吗?感谢

0 个答案:

没有答案