Reputation: 307
debug image hereBluetoothActivity.Java [debug image 2][2]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bluetooth_main);
//myLabel = (TextView)findViewById(R.id.label);
toggleButton = (ToggleButton) findViewById(R.id.toggleButton);
listview = (ListView) findViewById(R.id.listView);
// ListView Item Click Listener
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item value
String itemValue = (String) listview.getItemAtPosition(position);
Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_LONG).show();
String MAC = itemValue.substring(itemValue.length() - 17);
Intent intent = new Intent(getApplicationContext(),Bluetooth_dataDisplay.class);
intent.putExtra("MAC",MAC);
startActivity(intent);
//BluetoothDevice bluetoothDevice = mBluetoothAdapter.getRemoteDevice(MAC);
// Initiate a connection request in a separate thread
//ConnectingThread t = new ConnectingThread(bluetoothDevice);
//t.start();
}
});
adapter = new ArrayAdapter
(this,android.R.layout.simple_list_item_1);
listview.setAdapter(adapter);
//verify bluetooth is supported on the device
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// Device does not support Bluetooth
if (mBluetoothAdapter == null) {
}
}//end oncreate
Bluetooth_datadisplay.Javabluetooth_datadisplay image
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bluetooth_datadisplay);
myLabel = (TextView)findViewById(R.id.label);
String MAC = getIntent().getStringExtra("MAC");
BluetoothDevice bluetoothDevice = mAdapter.getRemoteDevice(MAC);
// Initiate a connection request in a separate thread
ConnectingThread t = new ConnectingThread(bluetoothDevice);
t.start();
}//end oncreate
Error
Attempt to invoke virtual method 'android.bluetooth.BluetoothDevice android.bluetooth.BluetoothAdapter.getRemoteDevice(java.lang.String)
' on a null object reference
Hi I trying to pass the Mac address of the bluetooth to bluetooth datadisplay. But I got the above error. Can anyone explain to me what wrong? Thank you!
Upvotes: 0
Views: 457
Reputation: 52810
You have not defined object of mAdapter.
BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice bluetoothDevice = mAdapter.getRemoteDevice(MAC);
Hope this will help you.
Upvotes: 1