closed #5188, fixed android NULL pointer exception

This commit is contained in:
andyque 2014-05-15 12:02:42 +08:00
parent 67f809e223
commit fc8d286fcb
1 changed files with 19 additions and 14 deletions

View File

@ -123,6 +123,7 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe
public boolean onEditorAction(final TextView pTextView, final int pActionID, final KeyEvent pKeyEvent) { public boolean onEditorAction(final TextView pTextView, final int pActionID, final KeyEvent pKeyEvent) {
if (this.mCocos2dxGLSurfaceView.getCocos2dxEditText() == pTextView && this.isFullScreenEdit()) { if (this.mCocos2dxGLSurfaceView.getCocos2dxEditText() == pTextView && this.isFullScreenEdit()) {
// user press the action button, delete all old text and insert new text // user press the action button, delete all old text and insert new text
if (null != mOriginText) {
for (int i = this.mOriginText.length(); i > 0; i--) { for (int i = this.mOriginText.length(); i > 0; i--) {
this.mCocos2dxGLSurfaceView.deleteBackward(); this.mCocos2dxGLSurfaceView.deleteBackward();
/* /*
@ -131,16 +132,20 @@ public class Cocos2dxTextInputWraper implements TextWatcher, OnEditorActionListe
} }
*/ */
} }
}
String text = pTextView.getText().toString(); String text = pTextView.getText().toString();
if (text != null) {
/* If user input nothing, translate "\n" to engine. */ /* If user input nothing, translate "\n" to engine. */
if (text.compareTo("") == 0) { if ( text.compareTo("") == 0) {
text = "\n"; text = "\n";
} }
if ('\n' != text.charAt(text.length() - 1)) { if ( '\n' != text.charAt(text.length() - 1)) {
text += '\n'; text += '\n';
} }
}
final String insertText = text; final String insertText = text;
this.mCocos2dxGLSurfaceView.insertText(insertText); this.mCocos2dxGLSurfaceView.insertText(insertText);