Home > Net >  NullPointerException: .... virtual method 'android.bluetooth.le.ScanRecord android.bluetooth.le
NullPointerException: .... virtual method 'android.bluetooth.le.ScanRecord android.bluetooth.le

Time:06-22

I'm using the function getScanRecord in this line of code :

if (!(this.mScanResult.getScanRecord().getServiceData() == null || this.mScanResult.getScanRecord().getServiceData().size() == 0)) { advertisementData = advertisementData "Service Data: " this.mScanResult.getScanRecord().getServiceData().toString().replace('{', ' ').replace('}', ' ') "\n"; }

And it gives me this error in Android Studio :

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.catu.catucomm/com.catu.catucomm.Second}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.bluetooth.le.ScanRecord android.bluetooth.le.ScanResult.getScanRecord()' on a null object reference

CodePudding user response:

Based on your error message, I suspect that your 'mScanResult' variable is empty. Check whether your 'mScanResult' is empty or not at that moment of code.

If you give me a full code, I might be able to help you more.

CodePudding user response:

I Have soved the problem by initializing the variable like this :

private ScanResult mScanResult;
public Second(ScanResult mScanResult) 
{
       this.mScanResult = mScanResult;
}

but now i have the new problem :

java.lang.InstantiationException: java.lang.Class<com.catu.catucomm.Second> has no zero argument constructor

  • Related