У меня есть страница входа, она работает нормально, когда я ввожу правильное имя пользователя и пароль, но для сбоя входа в систему не работает, как с этим справиться.
В Android я понятия не имею, если кто-то может предоставить код, пожалуйста
вот мой код :
package com.android;
import java.io.IOException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import org.json.JSONException;
import org.json.JSONObject;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.*;
public class Login extends Activity {
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL ="http:.asmx?op=LoginRequest";
private static final String SOAP_ACTION = "http://tempuri.org/Login";
//private String login="";
private static final String METHOD_NAME = "Login";
ImageButton login_button,sign_button;
TextView m,p,f,email,password,forgot_password;
EditText emailid,epassword;
AlertDialog authProgressDialog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.login);
email=(TextView)findViewById(R.id.email);
password=(TextView)findViewById(R.id.password);
forgot_password=(TextView)findViewById(R.id.forgot);
Context context = email.getContext();
Typeface font=Typeface.createFromAsset(context.getAssets(),"arial.ttf");
email.setTypeface(font);
Context con = password.getContext();
Typeface face=Typeface.createFromAsset(con.getAssets(),"arial.ttf");
password.setTypeface(face);
Context con1 = forgot_password.getContext();
Typeface face1=Typeface.createFromAsset(con1.getAssets(),"arial.ttf");
forgot_password.setTypeface(face1);
// new theTask().execute();
login_button=(ImageButton)findViewById(R.id.login);
sign_button=(ImageButton)findViewById(R.id.signup);
login_button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
String username,password;
emailid =(EditText)findViewById(R.id.edemail);
epassword =(EditText)findViewById(R.id.edpassword);
username = emailid.getText().toString();
password = epassword.getText().toString();
showDialog(0);
// TODO Auto-generated method stub
SoapObject request=new SoapObject(NAMESPACE,METHOD_NAME);
String qry="{\"General\":"+"{\"type\": \"Request\","+"\"application\": \"Mmmmm\","+"\"appver\": \"1.0.0\","+"\"phoneDeviceID\": \"123456789\","+"\"deviceType\": \"Android\","+"\"deviceOSVersion\": \"3.0\"},"+"\"Login\":"+"{\"emailID\":"+"\""+username+"\","+"\"password\":"+"\""+password+"\""+"}"+"}";
Log.i("Input",qry);
request.addProperty("JSONRequestString",qry);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.bodyOut=request;
envelope.encodingStyle=SoapSerializationEnvelope.ENC2001;
envelope.setOutputSoapObject(request);
AndroidHttpTransport androidHttpTransPort= new AndroidHttpTransport(URL);
try
{
try {
androidHttpTransPort.call(SOAP_ACTION,envelope);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SoapPrimitive rest=(SoapPrimitive)envelope.getResponse();
Log.i("output","Result"+rest );
// SoapObject var = (SoapObject)rest.getProperty(0);
String conv=rest.toString();
JSONObject js=new JSONObject(conv);
String login = js.getString("Login");
JSONObject err=new JSONObject(login);
String messcode=js.getString("HomePageFooterNewUpdates");
JSONObject code=new JSONObject(messcode);
int GetMessageCode=code.getInt("noOfMail");
Log.i("message code ","is " +GetMessageCode);
// String errc=err.getString("errorMsg");
// Log.i("err",errc);
int ResponseForLogin=err.getInt("errorCode");
Log.i("Response ","is "+ResponseForLogin);
if(ResponseForLogin==000){
Toast.makeText(Login.this, "Login Successfull", Toast.LENGTH_LONG).show();
// prepare the dialog box
/* ProgressDialog dialog = new ProgressDialog(this);
// make the progress bar Cancelable
dialog.setCancelable(true);
// set a message text
dialog.setMessage("Loading...");
// show it
dialog.show();*/
Intent i=new Intent(Login.this,Home.class);
i.putExtra("messcode", GetMessageCode);
startActivity(i);
} else {
Toast.makeText(Login.this, "Invalid Emailid or Password...Please Try Again", Toast.LENGTH_LONG).show();
}
}catch (XmlPullParserException e) {
e.printStackTrace();
}
catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SoapFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} );
sign_button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
Intent i=new Intent(Login.this, Signup.class);
startActivity(i);
}
});
}
}
Заранее спасибо ...