Soft Keyboard getting NullPointerException when calling canvas.drawtext
问题 I am working on SoftKeyboard where i need to display text on keys as shown below by red blocks As given in this reference and this reference, I am using below code, protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } Paint paint = new Paint(); paint.setTextSize(15); paint.setColor(Color.RED); int x2 = 0; int y2 = 0; int width = 0; List<Key> keys = SoftKeyboard.currentKeyboard.getKeys(); for(Key key: keys) { if(key.codes[0] == 113) x2 = key.x; // value of x2 =