The problem is that not every device has a name. If it scans a device without name and shows in logcat, it gives null and crash. To solve it just add if statement and check whether getName is null.
getName