我想掃描可用的藍牙設備並將它們顯示在列表中。我是新手和發展的新手。我想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