元源 发表于 2017-7-8 01:48:27

发现 机智云自动生成 Android App 代码中的一处Bug

Android 框架程序版本 :2.5.0.022212
SDK版本 : 2.06.06.11617
Bug 所在文件 : GosControlModuleBaseActivity.java
Bug 所在方法 : protected void hideKeyBoard()
出现 Bug的代码语句 : ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(GosControlModuleBaseActivity.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);

原因 : GosControlModuleBaseActivity.this.getCurrentFocus() 可能返回 null

建议 使用 try ... catch 包含此代码 或使用 更稳妥的判断代码,如:
protected void hideKeyBoard() {
                if(getSystemService(INPUT_METHOD_SERVICE) != null)
                {
                        InputMethodManager im = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                        if(GosControlModuleBaseActivity.this.getCurrentFocus() != null)
                        {
im.hideSoftInputFromWindow(GosControlModuleBaseActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                        }
                }

元源 发表于 2017-7-18 15:19:48

正常运行时,未出现此bug, 联机调试时,可能会遇到

AIcainiao 发表于 2017-9-18 11:30:09

厉害!!!
页: [1]
查看完整版本: 发现 机智云自动生成 Android App 代码中的一处Bug