I am getting an error on java.lang.NullPointerException

I am getting this error can anybody help me out please

public class MainActivity extends AppCompatActivity {
    Context context;
    BeaconManager beaconManager = new BeaconManager(getApplicationContext());
    private boolean notificationAlreadyShown = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       // EstimoteSDK.initialize(getApplicationContext(), "<#App ID#>", "<#App Token#>");
        beaconManager.setLocationListener(new BeaconManager.LocationListener() {
            @Override
            public void onLocationsFound(List<EstimoteLocation> beacons) {
                Log.d("LocationListener", "Nearby beacons: " + beacons);
            }
        });
        beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
            @Override public void onServiceReady() {
                beaconManager.startLocationDiscovery();
            }
        });

    }
    @Override
    protected void onResume() {
        super.onResume();
        SystemRequirementsChecker.checkWithDefaultDialogs(this);
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        beaconManager.disconnect();
    }
    public void showNotification(String title, String message) {
        if (notificationAlreadyShown) { return; }

        Intent notifyIntent = new Intent(this, MainActivity.class);
        notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivities(this, 0,
                new Intent[] { notifyIntent }, PendingIntent.FLAG_UPDATE_CURRENT);
        Notification notification = new Notification.Builder(this)
                .setSmallIcon(android.R.drawable.ic_dialog_info)
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setContentIntent(pendingIntent)
                .build();
        notification.defaults |= Notification.DEFAULT_SOUND;
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(1, notification);
        notificationAlreadyShown = true;
    }
    public void onLocationsFound(List<EstimoteLocation> beacons) {
        Log.d("LocationListener", "Nearby beacons: " + beacons);

        // replace with an identifier of your own beacon
        // you can find the identifier on the Estimote Cloud "Beacons" dashboard
        // or in the Estimote app from the Google Play Store
        String beaconId = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";

        for (EstimoteLocation beacon : beacons) {
            if (beacon.id.toString().equals(beaconId)
                    && RegionUtils.computeProximity(beacon) == Proximity.NEAR) {
                showNotification("Hello world", "Looks like you're near a beacon.");
            }
        }
    }
}

it’s very difficult to say, where the error happens.
Can you please post the complete error message?

Stacktrace would be necessary to diagnose where exception is thrown. What exact SDK version are you using?

E/AndroidRuntime: FATAL EXCEPTION: main
Process: beacon_project.nearby, PID: 16065
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{beacon_project.nearby/beacon_project.nearby.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.Context android.content.Context.getApplicationContext()’ on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3133)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7407)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘android.content.Context android.content.Context.getApplicationContext()’ on a null object reference
at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:112)
at beacon_project.nearby.MainActivity.(MainActivity.java:22)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1096)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3123)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
at android.app.ActivityThread.access$1100(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7407)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

compile fileTree(dir: ‘libs’, include: [’*.jar’])
compile ‘com.estimote:sdk:1.4.1’

Stack trace indicates it has nothing to do with Estimote SDK. It seems that you are calling getApplicationContext() in initialisation block, before onCreate method is called. This results in getApplicationContext() throwing NPE. Here is some more info

Looks like you haven’t initialised the EstimoteSDK credentials.

Per TUTORIAL you’ll need to call > CloudCredentials cloudCredentials =

    new EstimoteCloudCredentials("APP ID", "APP TOKEN");

inside your onCreate method for your “MainActivity” class.

Also while you’re initialising your BeaconManager in the Field there - it hasn’t been created while the app is launching so it cannot get applicationContext per se. It is safer to create this in the onCreate method as well.