title: Application crashes when I execute Keyboard.SetShifted
body: <p>I am trying to make a custom soft keyboard, my problem comes when I try to use the method setshifted of my keyboard, application get crashed.</p>
  
  <p>Here is my output error:</p>
  
  <blockquote>
    <p>02-19 19:58:45.649 2222-2222/? E/InputEventReceiver: Exception
    dispatching input event. 02-19 19:58:45.649 2222-2222/?
    E/MessageQueue-JNI: Exception in MessageQueue callback:
    handleReceiveCallback 02-19 19:58:45.649 2222-2222/?
    E/MessageQueue-JNI: java.lang.StringIndexOutOfBoundsException:
    length=0; index=0
                                                           at java.lang.String.indexAndLength(String.java:584)
                                                           at java.lang.String.charAt(String.java:578)
                                                           at android.inputmethodservice.KeyboardView.adjustCase(KeyboardView.java:577)
                                                           at android.inputmethodservice.KeyboardView.onBufferDraw(KeyboardView.java:687)
                                                           at android.inputmethodservice.KeyboardView.invalidateKey(KeyboardView.java:1054)
                                                           at android.inputmethodservice.KeyboardView.onModifiedTouchEvent(KeyboardView.java:1348)
                                                           at android.inputmethodservice.KeyboardView.onTouchEvent(KeyboardView.java:1209)
                                                           at android.view.View.dispatchTouchEvent(View.java:7706)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                           at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                           at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
                                                           at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
                                                           at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
                                                           at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                           at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                           at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
                                                           at android.view.View.dispatchPointerEvent(View.java:7886)
                                                           at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3978)
                                                           at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3857)
                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
                                                           at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
                                                           at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3549)
                                                           at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3450)
                                                           at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3606)
                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
                                                           at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
                                                           at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
                                                           at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3450)
                                                           at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
                                                           at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5626)
                                                           at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5606)
                                                           at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5577)
                                                           at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5706)
                                                          at android.view.InputEventReceiver.dis 02-19 19:58:45.649 2222-2222/?
    D/AndroidRuntime: Shutting down VM 02-19 19:58:45.649 2222-2222/?
    W/dalvikvm: threadid=1: thread exiting with uncaught exception
    (group=0x94c9bb20) 02-19 19:58:45.649 2222-2222/? E/AndroidRuntime:
    FATAL EXCEPTION: main
                                                     Process: app.parkinghelper.com.parkinghelper11, PID: 2222
                                                     java.lang.StringIndexOutOfBoundsException: length=0; index=0
                                                         at java.lang.String.indexAndLength(String.java:584)
                                                         at java.lang.String.charAt(String.java:578)
                                                         at android.inputmethodservice.KeyboardView.adjustCase(KeyboardView.java:577)
                                                         at android.inputmethodservice.KeyboardView.onBufferDraw(KeyboardView.java:687)
                                                         at android.inputmethodservice.KeyboardView.invalidateKey(KeyboardView.java:1054)
                                                         at android.inputmethodservice.KeyboardView.onModifiedTouchEvent(KeyboardView.java:1348)
                                                         at android.inputmethodservice.KeyboardView.onTouchEvent(KeyboardView.java:1209)
                                                         at android.view.View.dispatchTouchEvent(View.java:7706)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
                                                         at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
                                                         at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
                                                         at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
                                                         at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
                                                         at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                         at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:71)
                                                         at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
                                                         at android.view.View.dispatchPointerEvent(View.java:7886)
                                                         at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3978)
                                                         at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3857)
                                                         at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
                                                         at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
                                                         at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
                                                         at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3549)
                                                         at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3450)
                                                         at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3606)
                                                         at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
                                                         at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
                                                         at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
                                                         at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3450)
                                                         at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
                                                         at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5626)
                                                         at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5606)
                                                         at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5577)
                                                      at android.view.ViewRootImpl$WindowInputEventReceive</p>
  </blockquote>
  
  <p>Constructor of the keyboard class       </p>
  
  <pre><code>ph_ckb_2(Activity host, View kbview, int viewid, int Layoutid1) {
  
          mHostActivity = host;
          m_RootView = kbview;
          i_kbid1 = Layoutid1;
  
          kb_1 = new Keyboard(mHostActivity, i_kbid1);
  
          mKeyboardView = (KeyboardView)m_RootView.findViewById(viewid);
          mKeyboardView.setKeyboard(kb_1);
          mKeyboardView.setPreviewEnabled(false);
  
          mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);
          // Hide the standard keyboard initially
          mHostActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
          hideCustomKeyboard();
  
      }
  </code></pre>
  
  <p>Input function</p>
  
  <pre><code>    @Override
      public void onKey(int primaryCode, int[] keyCodes) {              
          View focusCurrent = mHostActivity.getWindow().getCurrentFocus();
  
          assert focusCurrent != null;
  
          Class&lt;? extends View&gt; GetTextClass = focusCurrent.getClass();
  
          if (GetTextClass == AppCompatEditText.class || GetTextClass == AppCompatAutoCompleteTextView.class) {
              EditText edittext = (EditText) focusCurrent;
              Editable editable = edittext.getText();
              int start = edittext.getSelectionStart();
              if (primaryCode == CodeShift) {
                  bShifted = !bShifted;
                  mKeyboardView.setShifted(bShifted);
                  mKeyboardView.invalidateAllKeys();                   
              } else { 
                  editable.insert(start, Character.toString((char) primaryCode));
              }
          }
      }
  </code></pre>
  
  <p>Original code here
  <a href="https://code.tutsplus.com/es/tutorials/create-a-custom-keyboard-on-android--cms-22615" rel="nofollow noreferrer">Crea un teclado personalizado en Android</a>
  and here 
  <a href="http://www.fampennings.nl/maarten/android/09keyboard/index.htm" rel="nofollow noreferrer">Android development: Custom keyboard</a></p>