0

i am making a bluetooth service in android studio. i execute the service in a single activity successfully using some post in stackOverFlow like : How to move Bluetooth activity into a Service but when i want to send data from a second activity that extends first activity, to the bluetooth device i got a "null object reference".

public void onClick(View v) {
            sendToDevice(editSendData.getText().toString());
        }

sendToDevice is a non-private method in MainActivity(first Activity):

public void sendToDevice(String inMain){

    printerService.sendingData(inMain);
    Log.i("3","thread id:\n"+"send1");
}

//printerService is bluetoothService

//sendData is a method in bluetoothService that uses bytes of "inMain" to send data using outputStream

i do not know why but as i know, when second activity extends first activity(an activity is class), it also extends non-private methods of first activity. so why this error occurs?

i did not find a question like this one but there was a question in the comment of another question simillar to my question but that wasn't answered.

thank you a lot.

any help would be appreciated.

mohammad rezza
  • 324
  • 1
  • 3
  • 17
  • When asking questions about code, please add a tag for the language in which you're coding. It helps get the question to the users who are most likely able to answer it. It also helps future site readers who are trying to find a language-specific solution to their problem, as your question will be included in search results using that language tag. Please [edit] to add that language tag. Thanks. – Ken White Apr 07 '21 at 21:23
  • Sorry. I am new to stackoverflow. – mohammad rezza Apr 08 '21 at 05:41

0 Answers0