android软件运行时抛出异常CheckedTextView cannot be cast to android.widget.ListView
android代码如下:BluetoothAdaptermadapter=BluetoothAdapter.getDefaultAdapter();ArrayList<S...
android代码如下:
BluetoothAdapter madapter = BluetoothAdapter.getDefaultAdapter();
ArrayList<String> list = new ArrayList<String>();
// Get a set of currently paired devices
Set<BluetoothDevice> pairedDevices = madapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
list.add(device.getName() + device.getAddress());
}
}
else {
String noDevices = getResources().getText(R.string.none_paired).toString();
list.add(noDevices);
}
ArrayAdapter<String> mPairedDevicesArrayAdapter = new ArrayAdapter<String>(
shebei.this,
android.R.layout.simple_list_item_1,
list);
ListView pairedListView = (ListView) findViewById(R.id.connected_shebei_name);
pairedListView.setAdapter(mPairedDevicesArrayAdapter); 展开
BluetoothAdapter madapter = BluetoothAdapter.getDefaultAdapter();
ArrayList<String> list = new ArrayList<String>();
// Get a set of currently paired devices
Set<BluetoothDevice> pairedDevices = madapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
list.add(device.getName() + device.getAddress());
}
}
else {
String noDevices = getResources().getText(R.string.none_paired).toString();
list.add(noDevices);
}
ArrayAdapter<String> mPairedDevicesArrayAdapter = new ArrayAdapter<String>(
shebei.this,
android.R.layout.simple_list_item_1,
list);
ListView pairedListView = (ListView) findViewById(R.id.connected_shebei_name);
pairedListView.setAdapter(mPairedDevicesArrayAdapter); 展开
1个回答
展开全部
这个异常很明显是转化异常:
CheckedTextView cannot be cast to android.widget.ListView
我怀疑是这段代码出现问题了,ListView pairedListView = (ListView) findViewById(R.id.connected_shebei_name)
connected_shebei_name应该是个textview,不能转化为listview
CheckedTextView cannot be cast to android.widget.ListView
我怀疑是这段代码出现问题了,ListView pairedListView = (ListView) findViewById(R.id.connected_shebei_name)
connected_shebei_name应该是个textview,不能转化为listview
追问
是把connected_shebei_list错打成了connected_shebei_name。太感谢啦
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询