私はこの問題を解決するために2日間努力しています。私はブルートゥースを有効または無効にするためのスイッチを作りました。まあ、私の主な活動に私が書いた:スイッチfindViewByIdが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リターンヌルを実行すると...あなたが任意のアイデアを持っていますか???
「R.id.bluetooth_switch」は正確にどこにありますか?あなたの活動または断片で。あなたが今アクティビティで検索しているからです。 –
あなたのフラグメントとそのアクティビティハットに含まれるxmlファイルを表示します – user3793589