首页 > 求大神帮忙看看代码 为什么if(CmdType==KEY)这里开始就不执行了呢

求大神帮忙看看代码 为什么if(CmdType==KEY)这里开始就不执行了呢

        @Override
        public void run() {            
                    try { 
                        while(true){                                                //无限循环来监听客户端是否有数据过来
                            if (msg!=null) {
                                try {
                                    
                                    JSONArray jsonObjs = new JSONArray(msg);
                                    Log.i("TService", "===============>aaaaa");
                                    for(int i=0;i<jsonObjs.length();i++){            //for循环读取客户端传过来的数据
                                        JSONObject jsonobj=(JSONObject) jsonObjs.get(i);//转成Object
                                        CmdType=jsonobj.getString("CmdType");
                                        CmdCode=jsonobj.getInt("CmdCode");
                                        CmdParam1=(float) jsonobj.getDouble("CmdParam1");  //读取数值强制转换成float
                                        CmdParam2=(float) jsonobj.getDouble("CmdParam2");    
                                        CmdParam3=jsonobj.getInt("CmdParam3");                                        
                                        Log.i("TService", CmdType);                                        
                                    }
                                    Log.i("TService", "==========>cccc");                                    
                                        if (CmdType==KEY) {
                                            Log.i("TService", "==========>bbb");
                                            try {
                                                
                                                Instrumentation instrumentation=new Instrumentation();
                                                instrumentation.sendKeyDownUpSync(CmdCode);
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        }    else if (CmdType==TOUCH) {
                                            Log.i("TService", "==========>dd");
                                            try {
                                                Instrumentation ins=new Instrumentation();
                                                ins.sendPointerSync(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), CmdCode, CmdParam1, CmdParam2, CmdParam3));
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        }
                                        else {
                                            
                                        }
                                    
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }                                 
                            }
                              break;                                     
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    
            
            
        }

这是代码log也只打印到===========>cccc 之后的if开始怎么就不执行了呢 这到底是怎么回事啊 求帮忙看看啊 真心谢谢了


java中字符串比较,使用equals方法


java中使用equals比较字符串的值,== 是判断引用的。

String str1 = "hello";
String str2 = new String("hello");

使用equals==比较这两个值有不同的答案,建议去试试。


判断用equals 试试

【热门文章】
【热门文章】