2013-06-06 2 views
1

asynctask에서 ksoap2를 사용하여 웹 서비스에 액세스하려고합니다. 나는 응용 프로그램 대신 웹 서비스의 응답을 실행할 때asynctask가 onPostExecute()를 실행하지 않습니다.

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.PropertyInfo; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapPrimitive; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.HttpTransportSE; 

import android.os.AsyncTask; 
import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.TextView; 

public class MainActivity extends Activity { 

private final String NAMESPACE = "http://eko.erdem.com"; 
private final String URL = "http://159.20.89.38:9398/EkoBiletTest/services/EkoClass?wsdl"; 
private final String SOAP_ACTION = "http://eko.erdem.com/homePage"; 
private final String METHOD_NAME = "homePage"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    hotelNetwork task = new hotelNetwork(); 
    task.execute(new String[]{NAMESPACE, URL, SOAP_ACTION, METHOD_NAME}); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.main, menu); 
    return true; 
} 

private class hotelNetwork extends AsyncTask<String[], Void, String> { 



    @Override 
    protected String doInBackground(String[]... params) { 

     String[] data = params[0]; 
     String namespace = data[0]; 
     String url = data[1]; 
     String action = data[2]; 
     String method = data[3]; 

     String result = ""; 
     SoapObject request = new SoapObject(namespace, method); 

     String place = "Paris"; 
     String checkinDate = "2013-06-10"; 
     String checkoutDate = "2013-06-12"; 

     //Pass value for place variable of the web service 
     PropertyInfo placeProp =new PropertyInfo(); 
     placeProp.setName("place");//Define the variable name in the web service method 
     placeProp.setValue(place);//Define value for place variable 
     placeProp.setType(String.class);//Define the type of the variable 
     request.addProperty(placeProp);//Pass properties to the variable 

     //Pass value for checkinDate variable of the web service 
     PropertyInfo checkinDateProp =new PropertyInfo(); 
     checkinDateProp.setName("checkinDate"); 
     checkinDateProp.setValue(checkinDate); 
     checkinDateProp.setType(String.class); 
     request.addProperty(checkinDateProp); 


     //Pass value for checkinDate variable of the web service 
     PropertyInfo checkoutDateProp =new PropertyInfo(); 
     checkoutDateProp.setName("checkoutDate"); 
     checkoutDateProp.setValue(checkoutDate); 
     checkoutDateProp.setType(String.class); 
     request.addProperty(checkoutDateProp); 



     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.setOutputSoapObject(request); 
     HttpTransportSE androidHttpTransport = new HttpTransportSE(url); 

     try { 
      androidHttpTransport.call(action, envelope); 
      SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
      result = response.toString(); 



     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return result; 
    } 

    @Override 
    protected void onPostExecute(String result){ 

     TextView tv = (TextView) MainActivity.this.findViewById(R.id.textView); 
     tv.setText(result); 
     MainActivity.this.setContentView(tv); 
    } 




} 
} 

텍스트 뷰는 여전히 기본 텍스트에 "Hello World"를 showes :이 코드를 썼다. 디버깅하고 doinBackground 메서드가 실제로 응답을 받고 반환하지만 onPostExecute는 호출되지 않은 것을 보았습니다. 이것의 원인은 무엇일까요? 이것은 doinBackground 메서드의 예외로 인해 발생할 수 있지만 예외는 표시되지 않는다고 들었습니다. 어떤 도움을 주시면 감사하겠습니다.

+1

왜 다시 주요 활동의 내용 없음을 설정하는 새로운 텍스트를 설정 한 후 "안녕하세요"를 말한다 다시 기본보기를 만드는 일을? 그 줄을 없애고 무슨 일이 일어나는가 보아라. – tyczj

+0

글쎄, 그걸로 해결했다. 왜 내가 그걸 받아 들일 수 있도록 대답으로 들어 가지 않는거야? – ManahManah

답변

2

MainActivity.this.setContentView(tv);을 제거 기본적으로 당신이 이미

관련 문제