我在java.lang.NullPointerException
上有错误
我已经宣布了我需要的一切。我需要做什么?
Java类
public class SearchTabloActivity extends AppCompatActivity {
ListView listView;
BluetoothAdapter mBluetoothAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search_tablo);
listView = (ListView)findViewById(R.id.listView);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
Toast.makeText(getApplicationContext(), "Bluetooth not support!", Toast.LENGTH_SHORT).show();
startActivity(new Intent(SearchTabloActivity.this, MainActivity.class));
}
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
List<String> s = new ArrayList<String>();
for(BluetoothDevice bt : pairedDevices)
s.add(bt.getName() + "\n" + bt.getAddress());
listView.setAdapter(new ArrayAdapter<String>(this, R.layout.activity_search_tablo, s));
}
}
错误
2020-04-24 09:47:56.208 12121-12121/com.kvaksmanyt.exoy E/AndroidRuntime: FATAL EXCEPTION: main Process: com.kvaksmanyt.exoy, PID: 12121 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kvaksmanyt.exoy/com.kvaksmanyt.exoy.tablo.SearchTabloActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.Set android.bluetooth.BluetoothAdapter.getBondedDevices()' on a null object reference
return
以任何void
方法停止代码