I tried to build an app that lets you send data over bluetooth to an arduino. But I got stuck while creating the socket. The app keeps crashing on startup, but I don't know why.
package de.lutherschule.bled.bluetoothled;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.icu.util.Output;
import android.support.annotation.WorkerThread;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import java.util.UUID;
public class MainActivity extends AppCompatActivity {
BluetoothAdapter bAdapter;
BluetoothDevice device;
Boolean found;
BluetoothSocket btSocket;
OutputStream outputStream;
InputStream inputStream;
public static final String DEVICE_ADRESS = "";
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private static final String TAG = "MainActvity";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    bAdapter = BluetoothAdapter.getDefaultAdapter();
    found = false;
    btSocket = null;
    Log.v(TAG, "Funst");
    if (bAdapter == null) {
        Toast.makeText(getApplicationContext(),"Funst net",Toast.LENGTH_SHORT).show();
    }
    if(!bAdapter.isEnabled()) {
        Intent enableAdapter = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableAdapter, 0);
    }
    Set<BluetoothDevice> bondedDevices = bAdapter.getBondedDevices();
    if(bondedDevices.isEmpty()) {
        Toast.makeText(getApplicationContext(),"Muss gepaired werden",Toast.LENGTH_SHORT).show();
    } else {
        for (BluetoothDevice iter : bondedDevices) {
            if(iter.getAddress().equals(DEVICE_ADRESS)) { // oder iter.getName() wenn Name bekannt muessen dann aendern
                device=iter;
                found=true;
                break;
            }
        }
    }
When I delete the section under this quote. The app starts just fine.
        try{
            btSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
        }catch(IOException ioe){
           Log.v(TAG, "socket nit erstellt");
        }
    }
    @Override
    public void onResume() {
        super.onResume();
        Intent intent = getIntent();
       device = bAdapter.getRemoteDevice(DEVICE_ADRESS);
        try {
            btSocket = device.createInsecureRfcommSocketToServiceRecord(MY_UUID);
        } catch (IOException e) {
            Toast.makeText(getBaseContext(), "Socket nit erstellt", Toast.LENGTH_LONG).show();
        }
        try {
        btSocket.connect();
        } catch (IOException e) {
            try {
                btSocket.close();
            } catch (IOException e2) {
            }
        }
    }
    @Override
    public void onPause() {
        super.onPause();
        try {
            btSocket.close();
        } catch (IOException e2) {
        }
    }
}
I'd appreciate any help. By the way sorry for my formatting... I'm a newbie in creating posts.
Android Monitor:
08-27 17:56:51.857 3071-3071/? E/libprocessgroup: failed to make and chown /acct/uid_10058: Read-only file system
08-27 17:56:51.857 3071-3071/? W/Zygote: createProcessGroup failed, kernel missing CONFIG_CGROUP_CPUACCT?
08-27 17:56:51.857 3071-3071/? I/art: Not late-enabling -Xcheck:jni (already on)
08-27 17:56:52.086 3071-3071/de.lutherschule.bled.bluetoothled I/InstantRun: Starting Instant Run Server for de.lutherschule.bled.bluetoothled
08-27 17:56:52.288 3071-3071/de.lutherschule.bled.bluetoothled W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
                                                                      [ 08-27 17:56:52.386  1162: 2146 D/         ]
                                                                      HostConnection::get() New Host Connection established 0xb68aea60, tid 2146
08-27 17:56:52.429 3071-3079/de.lutherschule.bled.bluetoothled W/art: Suspending all threads took: 17.085ms
08-27 17:56:52.442 3071-3071/de.lutherschule.bled.bluetoothled E/BluetoothAdapter: Bluetooth binder is null
08-27 17:56:52.442 3071-3071/de.lutherschule.bled.bluetoothled V/MainActvity: Funst
08-27 17:56:52.452 3071-3071/de.lutherschule.bled.bluetoothled D/AndroidRuntime: Shutting down VM
--------- beginning of crash
08-27 17:56:52.453 3071-3071/de.lutherschule.bled.bluetoothled E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: de.lutherschule.bled.bluetoothled, PID: 3071
                                                                                 java.lang.RuntimeException: Unable to start activity ComponentInfo{de.lutherschule.bled.bluetoothled/de.lutherschule.bled.bluetoothled.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothAdapter.isEnabled()' on a null object reference
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                     at android.os.Looper.loop(Looper.java:135)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                                     at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                                  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothAdapter.isEnabled()' on a null object reference
                                                                                     at de.lutherschule.bled.bluetoothled.MainActivity.onCreate(MainActivity.java:59)
                                                                                     at android.app.Activity.performCreate(Activity.java:5990)
                                                                                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                                                                                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                                     at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                     at android.os.Looper.loop(Looper.java:135) 
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                                     at java.lang.reflect.Method.invoke(Native Method) 
                                                                                     at java.lang.reflect.Method.invoke(Method.java:372) 
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 
 
     
    