이 문제를 해결하는 데 2 일이 걸립니다. 나는 블루투스를 켜고 끌 수있는 스위치를 만든 단편을 만들었습니다. 그럼 내 주요 활동에서 내가 쓴 :Switch findViewById returns null
clicked = new ButtonClicked();
과 : 클릭
bluetoothSwitch = (Switch) findViewById(R.id.bluetooth_switch);
bluetoothSwitch.setOnClickListener(clicked);
class ButtonClicked implements AdapterView.OnClickListener
{
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.bluetooth_switch:
if (bluetoothAdapter.isEnabled()){
bluetoothAdapter.disable();
Log.d("Log", "Bluetooth is disabled");
}
else{
bluetoothAdapter.enable();
Log.d("Log", "Bluetooth is enabled");
}
break;
case R.id.buttonSearch:
arrayListBluetoothDevices.clear();
startSearching();
break;
case R.id.discoverable_switch:
makeDiscoverable();
break;
default:
break;
}
}
}
을 나는 그것에게 findViewById를 반환 널 (null)을 실행할 때 ... 당신이 어떤 생각을 가지고 있습니까 ???
'R.id.bluetooth_switch'는 정확히 어디에 있습니까? 귀하의 활동 또는 단편. 왜냐하면 지금 당신은 활동을 찾고 있습니다. –
조각에 대한 xml 파일을 표시하고 활동 모자에 포함되어 있습니다. – user3793589