WebServiceからデータを取得する非同期タスクを実装しました。ただし、デバイスにアクティブなInternetConnectionがない場合、またはtryブロックで何かが発生した場合は例外が発生し、アプリケーションがクラッシュします。 ..私は、「ついに」句でその動作を妨げることを試みた..しかし、デバッガは非同期タスクの試行/キャッチ
try{
this.kantinen = new KantinenListe();
Gson gson = new Gson();
// SOAP Test
String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "fullSyncGPS";
String SOAP_ACTION = "http://tempuri.org/IDatenService/fullSyncGPS";
String URL = "Currywurst.svc?wsdl";
SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
request.addProperty("radius",10);
request.addProperty("lat", Double.toString(currentLocation.getLatitude()));
request.addProperty("lng", Double.toString(currentLocation.getLongitude()));
request.addProperty("von", "01.09.2011");
request.addProperty("bis", "05.09.2011");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
String resultData = result.toString();
resultData = "{\"meineKantinen\":"+resultData+"}";
this.kantinen = gson.fromJson(resultData, KantinenListe.class);
}
catch(Exception e)
{
//todo: implement
}
finally
{
return this.kantinen;
}
finallyブロックは決してヒットしないと言いますが、キャッチブロックはどうですか?例外が発生した場合、catchブロックがヒットするはずです。 – Jack