2012-08-04 2 views
1

내 버튼 클릭 이벤트에 위의 코드를 써야합니다. webservice 작업 fine.webservice 메서드는 문자열을 반환합니다. thatString은 성공과 같습니다. 다음 layout.it은 정상적으로 작동합니다. 그렇지 않으면 부분적으로 작동하지 않습니다. 토스트는 예외를 만든다호출 웹 서비스 메서드에서 스레드를 처리 할 수 ​​없습니다?

final SoapSerializationEnvelope envelope1 = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
      envelope1.setOutputSoapObject(request1); 

      //msg.setText("hi"); 
      envelope1.dotNet = true; 


      final Thread webser=new Thread(){ 
       public void run() 
       { 
        try { 
         HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
         System.out.println("four and Object value is : " +androidHttpTransport); 
         System.out.println("four and URL : " +URL); 
         //this is the actual part that will call the webservice 

         androidHttpTransport.call(SOAP_ACTION, envelope1); 

         System.out.println("four a"); 
         // Get the SoapResult from the envelope body. 

         SoapObject result1 = (SoapObject)envelope1.bodyIn; 



         if(result1 != null) 
         { 
           //Get the first property and change the label text 


          status=result1.getProperty(0).toString(); 
          if(status.equalsIgnoreCase("success")) 
          { 

           Intent home=new Intent(LoginActivity.this,MainActivity.class); 
           startActivity(home); 

          } 
          else         

          { 
           Thread.sleep(1000); 


          Toast.makeText(LoginActivity.this,"Enter Valid Username/Password", Toast.LENGTH_LONG).show(); 
          } 


         } 


         else 
         { 

          System.out.println("nodata"); 
         } 
        } catch (Exception e) { 
         e.printStackTrace(); 
         System.out.println("Exception" +e); 
        } 
       } 


      }; 
      webser.start(); 




     } 
    }); 
+0

"작동하지 않습니다."는 설명하기에 충분하지 않습니다. 좀 더 설명 해주십시오. – JoxTraex

+0

내 버튼 클릭 이벤트에 위의 코드를 써야합니다. webservice 작업 fine.webservice 메서드는 문자열을 반환합니다. thatString은 성공과 같습니다. 다음 layout.it은 정상적으로 작동합니다. 그렇지 않으면 부분적으로 작동하지 않습니다. 토스트는 예외를 만든다 – Palaniraja

+0

의견이 아닌 게시물에서이를 분명하게 작성하십시오. – JoxTraex

답변

1

당신은 뒤쪽 스레드에서 UI에 액세스하고 있습니다. .. 이런 식으로 Thread 사용에서

LoginActivity.this.runOnUiThread(new run Runnable() { 

     @Override 
     public void run() { 
      Toast.makeText(LoginActivity.this,"Enter Valid Username/Password", Toast.LENGTH_LONG).show(); 

     } 
    }); 

을 UI를 modife하고 (Exception e)를 잡을 수 없습니다. 나쁜 프로그래밍 실습입니다. :)

+0

덕분에 문제가 없습니다. – Palaniraja

+0

만약 당신이 다음 대답을 수락하는 데 도움이 :) –

+0

나는 below15 명성을 가지고. – Palaniraja

관련 문제