Android Studio Bluetooth :- attempt to invoke a virtual method on a null object reference
<p>I am building a simple app which switches on the Bluetooth of a device and sets it to visible.</p>

<p>I have a separate java class file which has the Bluetooth functions I need, and these are called from another java class which is linked to my activity, through an object of the said class.</p>

<p>This is my code:</p>

<pre><code>import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by mark on 11/11/2016.
 */

public class Bluetooth_API extends AppCompatActivity{

    BluetoothAdapter blueAdp;

    public Bluetooth_API() {
        blueAdp = BluetoothAdapter.getDefaultAdapter();
    }

    protected int bluetooth_ON() {
        startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), 0);
        //blueAdp.enable(); //instead of above line - without alert dialog for permission
        return 0;
    }

    protected int bluetooth_OFF() {
        blueAdp.disable(); //
        return 0;
    }

    protected int bluetooth_setVisible() {
        if(!blueAdp.isDiscovering()) {
            startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE), 0);
        }
        return 0;
    }

}
</code></pre>

<p>And this is the part of the code from the other activity which is calling my functions:</p>

<pre><code> scanButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent nextLayout = new Intent(getApplicationContext(), com.ai.mark.robot_dancing.Scanning_Devices.class);
                startActivity(nextLayout);
                blue.bluetooth_ON();
                //blue.bluetooth_setVisible();
            }
        });
</code></pre>

<p>I am getting the error below once I run my code, I believe it has to do with the activity not being the right one since my Bluetooth functions are in another file (I also tried copying the methods to my activity class and they worked beautifully).</p>

<p>Error:</p>

<blockquote>
  <p>E/AndroidRuntime: FATAL EXCEPTION: main
                    Process: com.ai.mark.robot_dancing, PID: 21314
                    java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.ActivityThread$ApplicationThread
  android.app.ActivityThread.getApplicationThread()' on a null object
  reference
                        at android.app.Activity.startActivityForResult(Activity.java:3951)
                        at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
                        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:77)
                        at android.app.Activity.startActivityForResult(Activity.java:3912)
                        at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
                        at com.ai.mark.robot_dancing.Bluetooth_API.bluetooth_ON(Bluetooth_API.java:20)
                        at com.ai.mark.robot_dancing.Bluetooth_Panel$6.onClick(Bluetooth_Panel.java:146)
                        at android.view.View.performClick(View.java:5210)
                        at android.view.View$PerformClick.run(View.java:21328)
                        at android.os.Handler.handleCallback(Handler.java:739)
                        at android.os.Handler.dispatchMessage(Handler.java:95)
                        at android.os.Looper.loop(Looper.java:148)
                        at android.app.ActivityThread.main(ActivityThread.java:5551)
                        at java.lang.reflect.Method.invoke(Native Method)
                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)</p>
</blockquote>

<p>Any ideas on what is causing this?
Thanks.</p>