Android 登录验证失败
我正在使用ksoap web服务进行用户登录。。但当我添加用户名和密码,然后得到消息登录失败…我如何解决它。。username=adc和password=adc已在web服务中存储 主课Android 登录验证失败,android,ksoap2,Android,Ksoap2,我正在使用ksoap web服务进行用户登录。。但当我添加用户名和密码,然后得到消息登录失败…我如何解决它。。username=adc和password=adc已在web服务中存储 主课 public class DotNetWSActivity extends Activity { static boolean errored = false; Button b; TextView tv; EditText et ,pw; boolean loginStatus; ProgressBar pg
public class DotNetWSActivity extends Activity {
static boolean errored = false;
Button b;
TextView tv;
EditText et ,pw;
boolean loginStatus;
ProgressBar pg;
String UserName ,Password;
String LoginAuthentication;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Name Text control
et = (EditText) findViewById(R.id.editText1);
pw = (EditText) findViewById(R.id.editText2);
//Display Text control
tv = (TextView) findViewById(R.id.tv_result);
//Button to trigger web service invocation
b = (Button) findViewById(R.id.button1);
//Display progress bar until web service invocation completes
pg = (ProgressBar) findViewById(R.id.progressBar1);
//Button Click Listener
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//Check if Name text control is not empty
if (et.getText().length() != 0 && et.getText().toString() != "") {
if (pw.getText().length() != 0 && pw.getText().toString() != "") {
//Get the text control value
UserName = et.getText().toString();
Password =pw.getText().toString();
//Create instance for AsyncCallWS
AsyncCallWS task = new AsyncCallWS();
//Call execute
task.execute();
//If text control is empty
} else {
tv.setText("Please enter name");
}
}else {
tv.setText("Please enter password");
}
}
});
}
private class AsyncCallWS extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... params) {
LoginAuthentication = WebService.invokeHelloWorldWS(UserName, Password,"LoginAuthentication");
return null;
}
protected void onPostExecute(Void result) {
// webservicePG.setVisibility(View.INVISIBLE);
Intent intObj = new Intent(DotNetWSActivity.this,dfdf.class);
//Error status is false
if(!errored){
//Based on Boolean value returned from WebService
if(loginStatus){
//Navigate to Home Screen
startActivity(intObj);
}else{
//Set Error message
tv.setText("Login Failed, try again");
}
//Error status is true
}else{
tv.setText("Error occured in invoking webservice");
}
//Re-initialize Error Status to False
errored = false;
}
protected void onPreExecute() {
pg.setVisibility(View.VISIBLE);
}
protected void onProgressUpdate(Void... values) {
}
}
}
日志:
07-24 12:13:47.121: W/System.err(1593): java.lang.NullPointerException
07-24 12:13:47.121: W/System.err(1593): at com.prgguru.android.WebService.invokeHelloWorldWS(WebService.java:50)
07-24 12:13:47.141: W/System.err(1593): at com.prgguru.android.DotNetWSActivity$AsyncCallWS.doInBackground(DotNetWSActivity.java:63)
07-24 12:13:47.151: W/System.err(1593): at com.prgguru.android.DotNetWSActivity$AsyncCallWS.doInBackground(DotNetWSActivity.java:1)
07-24 12:13:47.151: W/System.err(1593): at android.os.AsyncTask$2.call(AsyncTask.java:264)
07-24 12:13:47.151: W/System.err(1593): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-24 12:13:47.151: W/System.err(1593): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-24 12:13:47.151: W/System.err(1593): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
07-24 12:13:47.151: W/System.err(1593): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-24 12:13:47.162: W/System.err(1593): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
07-24 12:13:47.162: W/System.err(1593): at java.lang.Thread.run(Thread.java:856)
有几件事
在你的后台
LoginAuthentication = WebService.invokeHelloWorldWS(UserName, Password,"LoginAuthentication");
您正在从尚未实例化的类调用方法。我建议在WebService中创建一个构造函数,并接受这3个参数,然后在类中使用getter返回resTxt。那么你给班级打电话的样子
WebService webservice = new WebService(UserName, Password,"LoginAuthentication");
String LoginAuthentication = webservice.getResTxt();
或者,如果您坚持保持当前的格式,您仍然必须首先调用新的WebService来实例化该类
您现在没有收到编译错误的唯一原因是因为您的invokeHelloWorldWS方法是静态的。。。就我所知,没有理由认为它是静态的
另外,您正在将NULL从doInBackground传递到onPostExecute。。。为什么?onPostExecute的要点是从doInBackground获取值并对其进行处理 哪一行是WebService.java:50?在WebService类中,您得到用户名和密码值了吗?首先检查。是的,我在webservice中获得了价值class@Jens意思是我不明白???@user3871733你在你班的第50行得到一个NPE。我要知道的是Webservice类中的第50行是什么?
WebService webservice = new WebService(UserName, Password,"LoginAuthentication");
String LoginAuthentication = webservice.getResTxt();