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