Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android try-catch语句后没有错误,但不会执行任何操作_Android - Fatal编程技术网

Android try-catch语句后没有错误,但不会执行任何操作

Android try-catch语句后没有错误,但不会执行任何操作,android,Android,我正在尝试使用web服务显示数据。代码没有给出错误,但单击按钮时,执行仅发生在try部分,除此之外没有执行任何内容 try { Toast.makeText(getApplicationContext(), "You r in try", Toast.LENGTH_LONG).show(); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

我正在尝试使用web服务显示数据。代码没有给出错误,但单击按钮时,执行仅发生在try部分,除此之外没有执行任何内容

try {
                 Toast.makeText(getApplicationContext(), "You r in try", Toast.LENGTH_LONG).show();
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                //this is the actual part that will call the webservice
                androidHttpTransport.call(SOAP_ACTION1, envelope);                
                // Get the SoapResult from the envelope body.
                SoapObject result = (SoapObject)envelope.bodyIn;
               //from here nothing executes but gives no error
                ****if(result != null**)
                {
                    Toast.makeText(getApplicationContext(), "You r in if", Toast.LENGTH_LONG).show();
                      //Get the first property and change the label text
                      tv1.setText(result.getProperty(0).toString());     
                }
                else
                {
                      Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
                }
          } catch (Exception e) {
                e.printStackTrace();
          }                         
        }
    });

您正在调用的几个方法抛出异常

try {
                 Toast.makeText(getApplicationContext(), "You r in try", Toast.LENGTH_LONG).show();
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                //this is the actual part that will call the webservice
                androidHttpTransport.call(SOAP_ACTION1, envelope);                
                // Get the SoapResult from the envelope body.
                SoapObject result = (SoapObject)envelope.bodyIn;
               //from here nothing executes but gives no error
                ****if(result != null**)
                {
                    Toast.makeText(getApplicationContext(), "You r in if", Toast.LENGTH_LONG).show();
                      //Get the first property and change the label text
                      tv1.setText(result.getProperty(0).toString());     
                }
                else
                {
                      Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
                }
          } catch (Exception e) {
                e.printStackTrace();
          }                         
        }
    });
“跳过”代码表示抛出了异常

try {
                 Toast.makeText(getApplicationContext(), "You r in try", Toast.LENGTH_LONG).show();
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                //this is the actual part that will call the webservice
                androidHttpTransport.call(SOAP_ACTION1, envelope);                
                // Get the SoapResult from the envelope body.
                SoapObject result = (SoapObject)envelope.bodyIn;
               //from here nothing executes but gives no error
                ****if(result != null**)
                {
                    Toast.makeText(getApplicationContext(), "You r in if", Toast.LENGTH_LONG).show();
                      //Get the first property and change the label text
                      tv1.setText(result.getProperty(0).toString());     
                }
                else
                {
                      Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
                }
          } catch (Exception e) {
                e.printStackTrace();
          }                         
        }
    });

在catch块中放一个祝酒词以确认。

您是否尝试过祝酒结果???您得到了什么?请清理您的项目并重试。也不要用吐司。使用Log.i(“标记”、“您的消息”);为什么不调试应用程序并在问题区域设置断点呢;上面这行代码并没有被执行,我通过放置toast进行了检查。我有一个更具体的问题:如果你在catch块中放置了toast,你看到那个toast了吗?如果您这样做,则会引发异常。
try {
                 Toast.makeText(getApplicationContext(), "You r in try", Toast.LENGTH_LONG).show();
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                //this is the actual part that will call the webservice
                androidHttpTransport.call(SOAP_ACTION1, envelope);                
                // Get the SoapResult from the envelope body.
                SoapObject result = (SoapObject)envelope.bodyIn;
               //from here nothing executes but gives no error
                ****if(result != null**)
                {
                    Toast.makeText(getApplicationContext(), "You r in if", Toast.LENGTH_LONG).show();
                      //Get the first property and change the label text
                      tv1.setText(result.getProperty(0).toString());     
                }
                else
                {
                      Toast.makeText(getApplicationContext(), "No Response",Toast.LENGTH_LONG).show();
                }
          } catch (Exception e) {
                e.printStackTrace();
          }                         
        }
    });