My Application keeps stopping, help me find the problem please : I'm having a problem with my application, the thing that it is supposed to do is send a message using volume key buttons on the phone. The problem now is that it keeps stopping and I do not know if it works. Here is the code guys, I also added some wake lock in order for my app to stay active even when phone is locked



public class MainActivity extends Activity {

    private final static int SEND_SMS_PERMISSION_REQUEST_CODE = 111;
    private Button sendMessage;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
        wl.acquire();
        setContentView(R.layout.activity_main);
        sendMessage = findViewById(R.id.send_message);
        final EditText phone = findViewById(R.id.phone_no);
        final EditText message = findViewById(R.id.message);
        sendMessage.setEnabled(false);


        if (checkPermission(Manifest.permission.SEND_SMS)) {
            sendMessage.setEnabled(true);
        } else {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, SEND_SMS_PERMISSION_REQUEST_CODE);
        }

        sendMessage.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String msg = message.getText().toString();
                String phonenumber = phone.getText().toString();

                if (!TextUtils.isEmpty(msg) && !TextUtils.isEmpty(phonenumber)) {

                    if (checkPermission(Manifest.permission.SEND_SMS)) {
                        SmsManager smsManager = SmsManager.getDefault();
                        smsManager.sendTextMessage(String.valueOf(phone), null, msg, null, null);
                    } else {
                        Toast.makeText(MainActivity.this, "Permission denied", Toast.LENGTH_SHORT).show();
                    }
                } else {
                    Toast.makeText(MainActivity.this, "Enter a message and a phone number", Toast.LENGTH_SHORT).show();
                }
            }
        });

    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            sendMessage.setEnabled(true);
            return true;
        } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
            sendMessage.setEnabled(true);
            return true;
        } else
            return super.onKeyDown(keyCode, event);
    }

    private boolean checkPermission(String permission) {
        int checkPermission = ContextCompat.checkSelfPermission(this, permission);
        return checkPermission == PackageManager.PERMISSION_GRANTED;
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case SEND_SMS_PERMISSION_REQUEST_CODE:
                if (grantResults.length > 0 && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                    sendMessage.setEnabled(true);
                }

                break;
        }
    }
}