I am keep on getting the NoClassDefFoundError
when my class is loaded.
The code is taken from BluetoothLeGatt project -
http://developer.android.com/samples/BluetoothLeGatt/project.html
My code:
// Device scan callback. private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() { //java.lang.NoClassDefFoundError... @Override public void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord) { runOnUiThread(new Runnable() { @Override public void run() { String msg= device.getAddress(); Log.d(TAG,msg); addItems(msg); } }); } };
Someone suggested that the error is because my device doesn't support BLE but I want to get rid of this error for any device. So if it doesn't support BLE feature then simply skip this error else continue with the call to this BluetoothAdapter.LeScanCallback
.
NOTE:
See this my previous SO post for more clarification.
Putting the BLE feature check as the first line onCreate() doesn't stop the crash --
@Override public void onCreate(Bundle savedInstanceState) { if (!bleCheck()) { Toast.makeText(getApplicationContext(), R.string.ble_not_supported, Toast.LENGTH_SHORT).show(); finish(); } //Rest of the code //Call to BLE Scan on button click that causes error.. } private boolean bleCheck() { boolean result = false; if (getPackageManager(). hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)){ result = true; } return result; }