i want make android ble scanner
no problem start this app but i want startscan and push start scan button then turn off this app
this is error code
E/BoostFramework: BoostFramework() : Exception_1 = java.lang.ClassNotFoundException: Didn't find class "com.qualcomm.qti.Performance" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib64, /vendor/lib64]]
V/BoostFramework: BoostFramework() : mPerf = null
D/ViewRootImpl@d967e4a[MainActivity]: ViewPostImeInputStage processPointer 1
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 15923
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.bluetooth.le.BluetoothLeScanner.startScan(java.util.List, android.bluetooth.le.ScanSettings, android.bluetooth.le.ScanCallback)' on a null object reference
at com.example.myapplication.MainActivity.startScan(MainActivity.java:182)
at com.example.myapplication.MainActivity.lambda$onCreate$0$MainActivity(MainActivity.java:141)
at com.example.myapplication.-$$Lambda$MainActivity$mssl4La-mhhX0ttBjD5v7QdktdI.onClick(lambda)
at android.view.View.performClick(View.java:6205)
at android.widget.TextView.performClick(TextView.java:11103)
at android.view.View$PerformClick.run(View.java:23653)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
this is my code in MainActivity
//// GUI variables
// text view for status
private TextView tv_status_;
// text view for read
private TextView tv_read_;
// button for start scan
private Button btn_scan_;
// button for stop connection
private Button btn_stop_;
// button for send dataenter code here
private Button btn_send_;
// button for show paired devices
private Button btn_show_;
// Tag name for Log message
private final static String TAG="Central";
// used to identify adding bluetooth names
private final static int REQUEST_ENABLE_BT= 1;
// used to request fine location permission
private final static int REQUEST_FINE_LOCATION= 2;
// scan period in milliseconds
private final static int SCAN_PERIOD= 5000;
// ble adapter
private BluetoothAdapter ble_adapter_;
// flag for scanning
private boolean is_scanning_= false;
// flag for connection
private boolean connected_= false;
// scan results
private Map<String, BluetoothDevice> scan_results_;
// scan callback
private ScanCallback scan_cb_;
// ble scanner
private BluetoothLeScanner ble_scanner_;
// scan handler
private Handler scan_handler_;
public final static String MAC_ADDR="18:62:E4:3C:2A:1B";
//BLE Scan Callback class
private class BLEScanCallback extends ScanCallback {
private Map<String, BluetoothDevice> cb_scan_results_;
//Constructor
BLEScanCallback(Map<String, BluetoothDevice> _scan_results ){
}
public void onScanResult(int _callback_type, ScanResult _result) {
Log.d(TAG, "onScanResult");
addScanResult(_result);
}
public void onScanFailed(int _error) {
Log.e(TAG,"BLE scan failed with code "+_error);
}
//add scan result
private void addScanResult(ScanResult _result) {
//get scanned device
BluetoothDevice device = _result.getDevice();
//get scanned device Mac address
String device_address = device.getAddress();
//add the device to the result list
cb_scan_results_.put(device_address, device);
//log
Log.d(TAG, "scan results device: " + device);
tv_status_.setText("add scanned device: "+ device_address);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//// get instances of gui objects
// status textview
tv_status_= findViewById( R.id.tv_status );
// read textview
tv_read_= findViewById( R.id.tv_read );
// scan button
btn_scan_= findViewById( R.id.btn_scan );
// stop button
btn_stop_= findViewById( R.id.btn_stop );
// send button
btn_send_= findViewById( R.id.btn_send );
// show button
btn_show_= findViewById( R.id.btn_show );
// ble manager
BluetoothManager ble_manager;
ble_manager = (BluetoothManager)getSystemService(Context.BLUETOOTH_SERVICE);
// set ble adapter
ble_adapter_ = ble_manager.getAdapter();
btn_scan_.setOnClickListener((v) -> {startScan(v); });
}
//start scan
private void startScan(View v) {
tv_status_.setText("Scanning...");
// check ble adapter and ble enabled
if(ble_adapter_ == null || !ble_adapter_.isEnabled()){
requestEnableBLE();
tv_status_.setText("Scanning Failed: ble not enabled");
return;
}
//Set scanfilter
//creat filter list
List<ScanFilter> filters = new ArrayList<>();
// create a scan filter with device mac address
ScanFilter scan_filter = new ScanFilter.Builder().setDeviceAddress(MAC_ADDR).build();
// add filter to list
filters.add(scan_filter);
//// scan settings
// set low power scan mode
ScanSettings settings= new ScanSettings.Builder().setScanMode( ScanSettings.SCAN_MODE_LOW_POWER ).build();
// Scan callback
scan_results_ = new HashMap<>();
scan_cb_= new BLEScanCallback(scan_results_);
//now ready to scan
//start scan
ble_scanner_.startScan(filters, settings, scan_cb_);
//set scanning flag
is_scanning_ = true;
}
// Request BLE enable
private void requestEnableBLE() {
Intent ble_enable_intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(ble_enable_intent, REQUEST_ENABLE_BT);
}
// Request Fine Location permission
private void requestLocationPermission() {
requestPermissions( new String[]{ Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_FINE_LOCATION );
}
protected void onResume() {
super.onResume();
//finish app if the BLE is not supported
if( !getPackageManager().hasSystemFeature( PackageManager.FEATURE_BLUETOOTH_LE ) ) {
finish();
}
}
}
give me some help