我想扫描可用的蓝牙设备并将它们显示在列表中。我是新手和发展的新手。我想ArrayAdapter存在一些问题,但无法找出确切的问题。在Eclipse中扫描可用于Android的蓝牙设备
当我运行该程序时,我得到一个异常The application stops unexpectedly
。你能帮我解决这个问题吗?
button2.setOnClickListener(new View.OnClickListener()
{
@SuppressWarnings("null")
public void onClick(View v)
{
ListView lv1 = (ListView) findViewById(R.id.myListView1);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// TODO Auto-generated method stub
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
// If there are paired devices
if (pairedDevices.size() > 0)
{
// Loop through paired devices
for (BluetoothDevice device : pairedDevices)
{
ArrayAdapter<String> mArrayAdapter = null;
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
/*final ArrayList<String> btDevices = new ArrayList<String>();
ArrayAdapter<String> aa = new ArrayAdapter<String>(CalcActivity.this,
android.R.layout.simple_list_item_1,
btDevices);
*/
lv1.setAdapter(mArrayAdapter);
}
}
}
});
我在mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
编辑变得异常: 忍住了我的代码,但我仍不能找出问题。
Discovering available bluetooth devices in android
发布您的LogCat输出。 – Reno