2012-08-04 57 views
1

我必须在我的按钮点击事件中写上面的代码。 webservice工作fine.webservice方法返回一个字符串。 thatString等于成功去下一个layout.it工作正常。但其他部分不起作用。烤面包做一个例外无法处理webservice方法调用中的线程?

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 2012-08-04 14:18:04

+0

我必须在我的按钮点击事件中写上面的代码。 webservice工作fine.webservice方法返回一个字符串。 thatString等于成功去下一个layout.it工作正常。但其他部分不起作用。吐司例外 – Palaniraja 2012-08-04 14:26:59

+0

请在您的文章中明确说明,而不是在评论中。 – JoxTraex 2012-08-04 14:28:42

回答

1

您是从回地面线程访问UI。要使用Thread UI modife这样..

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

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

     } 
    }); 

而且不抓(Exception e)。这是不好的编程习惯。 :)

+0

感谢它的工作正常。 – Palaniraja 2012-08-06 15:36:54

+0

如果它可以帮助你,然后接受答案:) – 2012-08-07 05:07:56

+0

我有below15声誉.so我不接受这个 – Palaniraja 2012-08-07 14:43:03

相关问题