Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/183.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android 4.0中mysql调用soap webservice的登录表单_Java_Android_Mysql_Web Services_Android Ksoap2 - Fatal编程技术网

Java android 4.0中mysql调用soap webservice的登录表单

Java android 4.0中mysql调用soap webservice的登录表单,java,android,mysql,web-services,android-ksoap2,Java,Android,Mysql,Web Services,Android Ksoap2,我必须开发一个单安卓应用程序 这里我使用了下面的代码 public class MainActivity extends Activity { String status; EditText username,userPassword; SoapSerializationEnvelope envelope; private final String NAMESPACE = "http://pricealert.com"; private final Strin

我必须开发一个单安卓应用程序

这里我使用了下面的代码

  public class MainActivity extends Activity {
  String status;
  EditText username,userPassword;
    SoapSerializationEnvelope envelope;
    private final String NAMESPACE = "http://pricealert.com";
    private final String URL = "http://192.168.2.102:8085/PriceAlert/services/Login?wsdl";
    private final String SOAP_ACTION = "http://pricealert.com/authentication";
    private final String METHOD_NAME = "authentication";
    private String uName;
    HttpTransportSE androidHttpTransport;
     /**Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

  username = (EditText) findViewById(R.id.tf_userName);
   userPassword = (EditText) findViewById(R.id.tf_password);

   Button login = (Button) findViewById(R.id.btn_login);
     login.setOnClickListener(new View.OnClickListener() {

   public void onClick(View arg0) {

      new LoginOperation().execute();

      }
     });
       }
      class LoginOperation extends AsyncTask<String, Void, String> {
      private ProgressDialog Dialog = new ProgressDialog(MainActivity.this);

      @Override
  protected String doInBackground(String... aurl) {
 // TODO Auto-generated method stub
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
 username = (EditText) findViewById(R.id.tf_userName);
 String user_Name = username.getText().toString();
 userPassword = (EditText) findViewById(R.id.tf_password);
 String user_Password = userPassword.getText().toString();

 //Pass value for userName variable of the web service 
 PropertyInfo unameProp =new PropertyInfo();
 unameProp.setName("username");//Define the variable name in the web service method
 unameProp.setValue(user_Name);//set value for userName variable
 unameProp.setType(String.class);//Define the type of the variable
 request.addProperty(unameProp);//Pass properties to the variable it means 
 //Pass value for Password variable of the web service

 PropertyInfo passwordProp =new PropertyInfo();
 passwordProp.setName("password");
 passwordProp.setValue(user_Password);
 passwordProp.setType(String.class);
 request.addProperty(passwordProp);

  envelope = new SoapSerializationEnvelope(
         SoapEnvelope.VER12);
 envelope.setOutputSoapObject(request);
 androidHttpTransport = new HttpTransportSE(URL);
 runOnUiThread(new Runnable() {
     @Override
     public void run() {
 try{

        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        status = response.toString();
        TextView result = (TextView) findViewById(R.id.tv_status);
        result.setText(response.toString());

                  }
       catch(Exception e){
         }
     }
     });
     return null;
      }

     protected void onPreExecute() {
    Dialog.setMessage("Loading...");
    Dialog.show();
    }

    protected void onPostExecute(String resultGot) {
    Dialog.dismiss();
       }
       }
             }
公共类MainActivity扩展活动{
字符串状态;
编辑文本用户名、用户密码;
信封;
私有最终字符串命名空间=”http://pricealert.com";
私有最终字符串URL=”http://192.168.2.102:8085/PriceAlert/services/Login?wsdl";
私有最终字符串SOAP_ACTION=”http://pricealert.com/authentication";
私有最终字符串方法\u NAME=“身份验证”;
私有字符串uName;
HttpTransportSE和HttpTransport;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
用户名=(EditText)findViewById(R.id.tf_用户名);
userPassword=(EditText)findViewById(R.id.tf_密码);
按钮登录=(按钮)findViewById(R.id.btn\u登录);
login.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图arg0){
新登录操作().execute();
}
});
}
类LoginOperation扩展了异步任务{
private ProgressDialog=新建ProgressDialog(MainActivity.this);
@凌驾
受保护的字符串背景(字符串…aurl){
//TODO自动生成的方法存根
SoapObject请求=新的SoapObject(名称空间、方法名称);
用户名=(EditText)findViewById(R.id.tf_用户名);
字符串user_Name=username.getText().toString();
userPassword=(EditText)findViewById(R.id.tf_密码);
字符串user_Password=userPassword.getText().toString();
//传递web服务的userName变量的值
PropertyInfo unameProp=新的PropertyInfo();
unameProp.setName(“username”);//在web服务方法中定义变量名
unameProp.setValue(user_Name);//为userName变量设置值
unameProp.setType(String.class);//定义变量的类型
request.addProperty(unameProp);//将属性传递给它所表示的变量
//传递web服务的密码变量的值
PropertyInfo passwordProp=新的PropertyInfo();
passwordProp.setName(“密码”);
passwordProp.setValue(用户密码);
passwordProp.setType(String.class);
request.addProperty(passwordProp);
信封=新的SoapSerializationEnvelope(
第12版);
envelope.setOutputSoapObject(请求);
androidHttpTransport=新的HttpTransportSE(URL);
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
试一试{
调用(SOAP_操作,信封);
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
status=response.toString();
TextView结果=(TextView)findViewById(R.id.tv_状态);
result.setText(response.toString());
}
捕获(例外e){
}
}
});
返回null;
}
受保护的void onPreExecute(){
setMessage(“加载…”);
Dialog.show();
}
受保护的void onPostExecute(字符串resultGot){
Dialog.dismise();
}
}
}
如果我必须在安卓2.2上添加应用程序,则意味着它工作正常,并返回成功和失败值


但是同样的代码在安卓4.0上运行意味着没有收到任何(成功或失败)toast消息,也没有在我的logcate窗口中收到任何错误???我的代码有什么问题???请为我提供一些解决这些问题的解决方案???

您正在UI线程上调用Web服务。那是违法行为。您不应该在UI线程上执行DB或网络操作。较新版本的Android对此要求更严格,这就是它在其他版本上工作的原因。默认情况下,doInBackground()中的代码在单独的线程上运行,因此不需要在UI线程上运行任何东西


若要在调用后更新UI,请使用

post the stack StrasceNothing is Incomes is means.?@AkshayJoy这意味着没有收到任何(成功或失败)toast消息,也没有在我的logcate窗口中收到任何错误???请提供一个示例应用程序供我再次使用handlerOn,在这种情况下,您不需要处理程序,因为异步任务位于活动本身中。只需在onPostExecute中更新文本视图,它就会工作。是的,它工作得很好。非常感谢您的宝贵评论