Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,731,235 Members 52,073 Now Online
XDA Developers Android and Mobile Development Forum

Receiving error: Cannot convert from element type Object

Tip us?
 
theBasher91
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 5
Join Date: Jan 2014
Default Receiving error: Cannot convert from element type Object

Hello,
As the title states, I'm receiving an error that says "Cannot convert from element type Object to Bluetooth Device. The following is the highlighted code:
Code:
if (pairedDevices.size() > 0) {

findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);//make title viewable

for (BluetoothDevice device : pairedDevices) {

mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());

}

} else {

mPairedDevicesArrayAdapter.add("no devices paired");

}
I have a feeling it has something to do with java generics, but I'm not quite sure how to fix it. Would anyone be able to offer help?
Thanks
 
deanwray
Old
#2  
deanwray's Avatar
Senior Member
Thanks Meter 406
Posts: 1,086
Join Date: Apr 2006

 
DONATE TO ME
Quote:
Originally Posted by theBasher91 View Post
Code:
for (BluetoothDevice device : pairedDevices)
Well I would suspect that pairedDevices is a list or array of type Object? Not sure as you dont post the actual error or line numbers... but cast within the for loop if this is the case

Code:
for (Object item : pairedDevices)
{
   BluetoothDevice device = (BluetoothDevice) item;
}
Just a thought
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes