在Android中登录尝试失败时app崩溃了

知识的领域是无限的,我们的学习也是无限期的。这篇文章主要讲述在Android中登录尝试失败时app崩溃了相关的知识,希望能为你提供帮助。
首先,我是android开发的新手。我正在尝试开发一个将在特定站点登录的应用程序,并将xml文件解析为来自该站点的响应。我已经编写了代码并且只在成功登录时才起作用,但是当登录失败时(不正确的用户名/密码),应用程序崩溃了。我也使用AsyncTask但仍然没有运气。检查代码以获取更多信息,

@Override public void onClick(View view) { if (view == ok) { new AttemptLogin().execute(); } }class AttemptLogin extends AsyncTask< String, String, String> {@Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(MainActivity.this); pDialog.setMessage("Attempting Login..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); }@Override protected String doInBackground(String... arg0) { // TODO Auto-generated method stub // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://www.mysite.com/finalplus/apiservice.php"); try { // Add user name, password & pin String action = "login"; EditText uname = (EditText) findViewById(R.id.etUsername); String username = uname.getText().toString(); EditText pword = (EditText) findViewById(R.id.etPassword); String password = pword.getText().toString(); EditText pcode = (EditText) findViewById(R.id.etPin); String pin = pcode.getText().toString(); List< NameValuePair> nameValuePairs = new ArrayList< NameValuePair> ( 4); nameValuePairs.add(new BasicNameValuePair("action", action)); nameValuePairs .add(new BasicNameValuePair("username", username)); nameValuePairs .add(new BasicNameValuePair("password", password)); nameValuePairs.add(new BasicNameValuePair("pin", pin)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); responseXML = httpclient.execute(httppost, new BasicResponseHandler()); // passing xml data to dom parser dom_parser(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }protected void onPostExecute(String file_url) { // dismiss the dialog once executed pDialog.dismiss(); if (ack.equals("SUCCESS")) {Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show(); Intent as = new Intent(MainActivity.this, AccountSummary.class); // add user data SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences(MainActivity.this); Editor edit = sp.edit(); edit.putString("username", username); edit.putString("ewallpoints", ewallpoints); edit.putString("name", name); edit.commit(); startActivity(as); as.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); finish(); }else { //setting an error message in the TextBox response_xml.setText("Incorrect Login!"); }} } } public void dom_parser() { try {// File stocks = new File(responseXML); DocumentBuilderFactory dbFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new InputSource(new StringReader( responseXML))); doc.getDocumentElement().normalize(); NodeList nodes = doc.getElementsByTagName("member"); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; ack = ((getValue("ack", element))); id = ((getValue("id", element))); username = ((getValue("username", element))); name = ((getValue("name", element))); ewallpoints = ((getValue("ewallpoints", element))); msg = ((getValue("msg", element))); } } } catch (Exception ex) { ex.printStackTrace(); response_xml.setText("error!"); }}private static String getValue(String tag, Element element) { NodeList nodes = element.getElementsByTagName(tag).item(0) .getChildNodes(); Node node = (Node) nodes.item(0); return node.getNodeValue(); }

这里'ack'是从xml输出解析的成功/失败消息!
< login> < member> < id/> < username/> < name/> < ewallpoints/> < ack> FAILED< /ack> < msg> Wrong Username and Password< /msg> < /member> < /login>

这是logcat输出,
06-18 11:13:18.216: I/ActivityManager(294): Start proc com.p2r.mobifin for activity com.p2r.mobifin/.MainActivity: pid=17984 uid=10050 gids={50050, 3003, 1028} 06-18 11:13:18.526: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property 06-18 11:13:18.656: E/Trace(17984): error opening trace file: No such file or directory (2) 06-18 11:13:19.406: D/dalvikvm(17984): GC_FOR_ALLOC freed 57K, 7% free 2499K/2676K, paused 56ms, total 58ms 06-18 11:13:19.436: I/dalvikvm-heap(17984): Grow heap (frag case) to 5.802MB for 3404596-byte allocation 06-18 11:13:19.546: D/dalvikvm(17984): GC_FOR_ALLOC freed 2K, 4% free 5821K/6004K, paused 109ms, total 109ms 06-18 11:13:19.596: D/dalvikvm(17984): GC_CONCURRENT freed < 1K, 4% free 5821K/6004K, paused 4ms+17ms, total 55ms 06-18 11:13:19.766: E/ActivityThread(434): Failed to find provider info for com.android.inputmethod.latin.dictionarypack 06-18 11:13:19.766: E/BinaryDictionaryGetter(434): Could not find a dictionary pack 06-18 11:13:19.906: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property 06-18 11:13:20.016: D/gralloc_goldfish(17984): Emulator without GPU emulation detected. 06-18 11:13:20.105: I/ActivityManager(294): Displayed com.p2r.mobifin/.MainActivity: +1s947ms 06-18 11:13:25.146: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property 06-18 11:13:26.866: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property 06-18 11:13:27.996: D/dalvikvm(17984): GC_CONCURRENT freed 96K, 4% free 6749K/6968K, paused 79ms+173ms, total 394ms 06-18 11:13:27.996: I/Choreographer(17984): Skipped 100 frames!The application may be doing too much work on its main thread. 06-18 11:13:28.396: I/Choreographer(17984): Skipped 37 frames!The application may be doing too much work on its main thread. 06-18 11:13:28.646: I/Choreographer(17984): Skipped 34 frames!The application may be doing too much work on its main thread. 06-18 11:13:29.306: I/Choreographer(17984): Skipped 33 frames!The application may be doing too much work on its main thread. 06-18 11:13:29.436: I/Choreographer(17984): Skipped 34 frames!The application may be doing too much work on its main thread. 06-18 11:13:29.666: I/Choreographer(17984): Skipped 30 frames!The application may be doing too much work on its main thread. 06-18 11:13:29.776: W/SingleClientConnManager(17984): Invalid use of SingleClientConnManager: connection still allocated. 06-18 11:13:29.776: W/SingleClientConnManager(17984): Make sure to release the connection before allocating another one. 06-18 11:13:30.145: I/Choreographer(17984): Skipped 32 frames!The application may be doing too much work on its main thread. 06-18 11:13:30.416: I/Choreographer(17984): Skipped 37 frames!The application may be doing too much work on its main thread. 06-18 11:13:30.826: W/System.err(17984): java.lang.NullPointerException 06-18 11:13:30.856: W/System.err(17984):at com.p2r.mobifin.MainActivity.getValue(MainActivity.java:104) 06-18 11:13:30.856: W/System.err(17984):at com.p2r.mobifin.MainActivity.dom_parser(MainActivity.java:86) 06-18 11:13:30.856: W/System.err(17984):at com.p2r.mobifin.MainActivity$AttemptLogin.doInBackground(MainActivity.java:165) 06-18 11:13:30.856: W/System.err(17984):at com.p2r.mobifin.MainActivity$AttemptLogin.doInBackground(MainActivity.java:1) 06-18 11:13:30.856: W/System.err(17984):at android.os.AsyncTask$2.call(AsyncTask.java:287) 06-18 11:13:30.856: W/System.err(17984):at java.util.concurrent.FutureTask.run(FutureTask.java:234) 06-18 11:13:30.856: W/System.err(17984):at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 06-18 11:13:30.856: W/System.err(17984):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 06-18 11:13:30.866: W/System.err(17984):at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 06-18 11:13:30.866: W/System.err(17984):at java.lang.Thread.run(Thread.java:856) 06-18 11:13:30.916: W/dalvikvm(17984): threadid=13: thread exiting with uncaught exception (group=0x40a71930) 06-18 11:13:31.066: E/AndroidRuntime(17984): FATAL EXCEPTION: AsyncTask #3 06-18 11:13:31.066: E/AndroidRuntime(17984): java.lang.RuntimeException: An error occured while executing doInBackground() 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.os.AsyncTask$3.done(AsyncTask.java:299) 06-18 11:13:31.066: E/AndroidRuntime(17984):at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 06-18 11:13:31.066: E/AndroidRuntime(17984):at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 06-18 11:13:31.066: E/AndroidRuntime(17984):at java.util.concurrent.FutureTask.run(FutureTask.java:239) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 06-18 11:13:31.066: E/AndroidRuntime(17984):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 06-18 11:13:31.066: E/AndroidRuntime(17984):at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 06-18 11:13:31.066: E/AndroidRuntime(17984):at java.lang.Thread.run(Thread.java:856) 06-18 11:13:31.066: E/AndroidRuntime(17984): Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4746) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:823) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.view.View.requestLayout(View.java:15473) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.view.View.requestLayout(View.java:15473) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.view.View.requestLayout(View.java:15473) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.view.View.requestLayout(View.java:15473) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:318) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.view.View.requestLayout(View.java:15473) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.view.View.requestLayout(View.java:15473) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.widget.TextView.checkForRelayout(TextView.java:6452) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.widget.TextView.setText(TextView.java:3696) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.widget.TextView.setText(TextView.java:3554) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.widget.TextView.setText(TextView.java:3529) 06-18 11:13:31.066: E/AndroidRuntime(17984):at com.p2r.mobifin.MainActivity.dom_parser(MainActivity.java:95) 06-18 11:13:31.066: E/AndroidRuntime(17984):at com.p2r.mobifin.MainActivity$AttemptLogin.doInBackground(MainActivity.java:165) 06-18 11:13:31.066: E/AndroidRuntime(17984):at com.p2r.mobifin.MainActivity$AttemptLogin.doInBackground(MainActivity.java:1) 06-18 11:13:31.066: E/AndroidRuntime(17984):at android.os.AsyncTask$2.call(AsyncTask.java:287) 06-18 11:13:31.066: E/AndroidRuntime(17984):at java.util.concurrent.FutureTask.run(FutureTask.java:234) 06-18 11:13:31.066: E/AndroidRuntime(17984):... 4 more 06-18 11:13:31.275: W/ActivityManager(294):Force finishing activity com.p2r.mobifin/.MainActivity 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: E/libEGL(36): called unimplemented OpenGL ES API 06-18 11:13:31.285: W/WindowManager(294): Failure taking screenshot for (246x410) to layer 21015 06-18 11:13:31.586: I/Choreographer(17984): Skipped 65 frames!The application may be doing too much work on its main thread. 06-18 11:13:31.736: I/Choreographer(557): Skipped 44 frames!The application may be doing too much work on its main thread. 06-18 11:13:31.856: I/Choreographer(294): Skipped 70 frames!The application may be doing too much work on its main thread. 06-18 11:13:31.856: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property 06-18 11:13:31.956: E/SurfaceFlinger(36): ro.sf.lcd_density must be defined as a build property 06-18 11:13:32.886: I/Choreographer(294): Skipped 53 frames!The application may be doing too much work on its main thread. 06-18 11:13:33.976: E/WindowManager(17984): Activity com.p2r.mobifin.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41063e50 V.E..... R.....ID 0,0-456,144} that was originally added here 06-18 11:13:33.976: E/WindowManager(17984): android.view.WindowLeaked: Activity com.p2r.mobifin.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{41063e50 V.E..... R.....ID 0,0-456,144} that was originally added here 06-18 11:13:33.976: E/WindowManager(17984):at android.view.ViewRootImpl.< init> (ViewRootImpl.java:354) 06-18 11:13:33.976: E/WindowManager(17984):at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216) 06-18 11:13:33.976: E/WindowManager(17984):at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69) 06-18 11:13:33.976: E/WindowManager(17984):at android.app.Dialog.show(Dialog.java:281) 06-18 11:13:33.976: E/WindowManager(17984):at com.p2r.mobifin.MainActivity$AttemptLogin.onPreExecute(MainActivity.java:123) 06-18 11:13:33.976: E/WindowManager(17984):at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586) 06-18 11:13:33.976: E/WindowManager(17984):at android.os.AsyncTask.execute(AsyncTask.java:534) 06-18 11:13:33.976: E/WindowManager(17984):at com.p2r.mobifin.MainActivity.onClick(MainActivity.java:110) 06-18 11:13:33.976: E/WindowManager(17984):at android.view.View.performClick(View.java:4204) 06-18 11:13:33.976: E/WindowManager(17984):at android.view.View$PerformClick.run(View.java:17355) 06-18 11:13:33.976: E/WindowManager(17984):at android.os.Handler.handleCallback(Handler.java:725) 06-18 11:13:33.976: E/WindowManager(17984):at android.os.Handler.dispatchMessage(Handler.java:92) 06-18 11:13:33.976: E/WindowManager(17984):at android.os.Looper.loop(Looper.java:137) 06-18 11:13:33.976: E/WindowManager(17984):at android.app.ActivityThread.main(ActivityThread.java:5041) 06-18 11:13:33.976: E/WindowManager(17984):at java.lang.reflect.Method.invokeNative(Native Method) 06-18 11:13:33.976: E/WindowManager(17984):at java.lang.reflect.Method.invoke(Method.java:511) 06-18 11:13:33.976: E/WindowManager(17984):at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-18 11:13:33.976: E/WindowManager(17984):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-18 11:13:33.976: E/WindowManager(17984):at dalvik.system.NativeStart.main(Native Method) 06-18 11:13:33.976: I/Choreographer(17984): Skipped 50 frames!The application may be doing too much work on its main thread. 06-18 11:13:59.272: D/ExchangeService(720): Received deviceId from Email app: null 06-18 11:13:59.272: D/ExchangeService(720): !!! deviceId unknown; stopping self and retrying 06-18 11:14:04.317: D/ExchangeService(720): !!! EAS ExchangeService, onCreate 06-18 11:14:04.336: D/ExchangeService(720): !!! EAS ExchangeService, onStartCommand, startingUp = false, running = false 06-18 11:14:04.345: W/ActivityManager(294): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found 06-18 11:14:04.356: D/ExchangeService(720): !!! EAS ExchangeService, onStartCommand, startingUp = true, running = false 06-18 11:14:04.356: D/ExchangeService(720): !!! Email application not found; stopping self 06-18 11:14:04.366: W/ActivityManager(294): Unable to start service Intent { act=com.android.email.ACCOUNT_INTENT } U=0: not found 06-18 11:14:04.386: E/ActivityThread(720): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d045c8 that was originally bound here 06-18 11:14:04.386: E/ActivityThread(720): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d045c8 that was originally bound here 06-18 11:14:04.386: E/ActivityThread(720):at android.app.LoadedApk$ServiceDispatcher.< init> (LoadedApk.java:969) 06-18 11:14:04.386: E/ActivityThread(720):at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863) 06-18 11:14:04.386: E/ActivityThread(720):at android.app.ContextImpl.bindService(ContextImpl.java:1418) 06-18 11:14:04.386: E/ActivityThread(720):at android.app.ContextImpl.bindService(ContextImpl.java:1407) 06-18 11:14:04.386: E/ActivityThread(720):at android.content.ContextWrapper.bindService(ContextWrapper.java:473) 06-18 11:14:04.386: E/ActivityThread(720):at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157) 06-18 11:14:04.386: E/ActivityThread(720):at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145) 06-18 11:14:04.386: E/ActivityThread(720):at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116) 06-18 11:14:04.386: E/ActivityThread(720):at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249) 06-18 11:14:04.386: E/ActivityThread(720):at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856) 06-18 11:14:04.386: E/ActivityThread(720):at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551) 06-18 11:14:04.386: E/ActivityThread(720):at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549) 06-18 11:14:04.386: E/ActivityThread(720):at android.os.AsyncTask$2.call(AsyncTask.java:287) 06-18 11:14:04.386: E/ActivityThread(720):at java.util.concurrent.FutureTask.run(FutureTask.java:234) 06-18 11:14:04.386: E/ActivityThread(720):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 06-18 11:14:04.386: E/ActivityThread(720):at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 06-18 11:14:04.386: E/ActivityThread(720):at java.lang.Thread.run(Thread.java:856) 06-18 11:14:04.386: E/StrictMode(720): null 06-18 11:14:04.386: E/StrictMode(720): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d045c8 that was originally bound here 06-18 11:14:04.386: E/StrictMode(720):at android.app.LoadedApk$ServiceDispatcher.< init> (LoadedApk.java:969) 06-18 11:14:04.386: E/StrictMode(720):at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863) 06-18 11:14:04.386: E/StrictMode(720):at android.app.ContextImpl.bindService(ContextImpl.java:1418) 06-18 11:14:04.386: E/StrictMode(720):at android.app.ContextImpl.bindService(ContextImpl.java:1407) 06-18 11:14:04.386: E/StrictMode(720):at android.content.ContextWrapper.bindService(ContextWrapper.java:473) 06-18 11:14:04.386: E/StrictMode(720):at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157) 06-18 11:14:04.386: E/StrictMode(720):at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145) 06-18 11:14:04.386: E/StrictMode(720):at com.android.emailcommon.service.AccountServiceProxy.getDeviceId(AccountServiceProxy.java:116) 06-18 11:14:04.386: E/StrictMode(720):at com.android.exchange.ExchangeService.getDeviceId(ExchangeService.java:1249) 06-18 11:14:04.386: E/StrictMode(720):at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1856) 06-18 11:14:04.386: E/StrictMode(720):at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551) 06-18 11:14:04.386: E/StrictMode(720):at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549) 06-18 11:14:04.386: E/StrictMode(720):at android.os.AsyncTask$2.call(AsyncTask.java:287) 06-18 11:14:04.386: E/StrictMode(720):at java.util.concurrent.FutureTask.run(FutureTask.java:234) 06-18 11:14:04.386: E/StrictMode(720):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 06-18 11:14:04.386: E/StrictMode(720):at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 06-18 11:14:04.386: E/StrictMode(720):at java.lang.Thread.run(Thread.java:856) 06-18 11:14:04.386: W/ActivityManager(294): Unbind failed: could not find connection for android.os.BinderProxy@412abcd0 06-18 11:14:04.406: E/ActivityThread(720): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d0dbc8 that was originally bound here 06-18 11:14:04.406: E/ActivityThread(720): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d0dbc8 that was originally bound here 06-18 11:14:04.406: E/ActivityThread(720):at android.app.LoadedApk$ServiceDispatcher.< init> (LoadedApk.java:969) 06-18 11:14:04.406: E/ActivityThread(720):at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863) 06-18 11:14:04.406: E/ActivityThread(720):at android.app.ContextImpl.bindService(ContextImpl.java:1418) 06-18 11:14:04.406: E/ActivityThread(720):at android.app.ContextImpl.bindService(ContextImpl.java:1407) 06-18 11:14:04.406: E/ActivityThread(720):at android.content.ContextWrapper.bindService(ContextWrapper.java:473) 06-18 11:14:04.406: E/ActivityThread(720):at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157) 06-18 11:14:04.406: E/ActivityThread(720):at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145) 06-18 11:14:04.406: E/ActivityThread(720):at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191) 06-18 11:14:04.406: E/ActivityThread(720):at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850) 06-18 11:14:04.406: E/ActivityThread(720):at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551) 06-18 11:14:04.406: E/ActivityThread(720):at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549) 06-18 11:14:04.406: E/ActivityThread(720):at android.os.AsyncTask$2.call(AsyncTask.java:287) 06-18 11:14:04.406: E/ActivityThread(720):at java.util.concurrent.FutureTask.run(FutureTask.java:234) 06-18 11:14:04.406: E/ActivityThread(720):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 06-18 11:14:04.406: E/ActivityThread(720):at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 06-18 11:14:04.406: E/ActivityThread(720):at java.lang.Thread.run(Thread.java:856) 06-18 11:14:04.406: E/StrictMode(720): null 06-18 11:14:04.406: E/StrictMode(720): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d0dbc8 that was originally bound here 06-18 11:14:04.406: E/StrictMode(720):at android.app.LoadedApk$ServiceDispatcher.< init> (LoadedApk.java:969) 06-18 11:14:04.406: E/StrictMode(720):at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863) 06-18 11:14:04.406: E/StrictMode(720):at android.app.ContextImpl.bindService(ContextImpl.java:1418) 06-18 11:14:04.406: E/StrictMode(720):at android.app.ContextImpl.bindService(ContextImpl.java:1407) 06-18 11:14:04.406: E/StrictMode(720):at android.content.ContextWrapper.bindService(ContextWrapper.java:473) 06-18 11:14:04.406: E/StrictMode(720):at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157) 06-18 11:14:04.406: E/StrictMode(720):at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145) 06-18 11:14:04.406: E/StrictMode(720):at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191) 06-18 11:14:04.406: E/StrictMode(720):at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850) 06-18 11:14:04.406: E/StrictMode(720):at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551) 06-18 11:14:04.406: E/StrictMode(720):at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549) 06-18 11:14:04.406: E/StrictMode(720):at android.os.AsyncTask$2.call(AsyncTask.java:287) 06-18 11:14:04.406: E/StrictMode(720):at java.util.concurrent.FutureTask.run(FutureTask.java:234) 06-18 11:14:04.406: E/StrictMode(720):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 06-18 11:14:04.406: E/StrictMode(720):at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 06-18 11:14:04.406: E/StrictMode(720):at java.lang.Thread.run(Thread.java:856) 06-18 11:14:04.416: W/ActivityManager(294): Unbind failed: could not find connection for android.os.BinderProxy@413e8d38 06-18 11:14:10.936: I/Process(17984): Sending signal. PID: 17984 SIG: 9 06-18 11:14:10.956: I/ActivityManager(294): Process com.p2r.mobifin (pid 17984) has died. 06-18 11:14:11.056: W/InputMethodManagerService(294): Got RemoteException sending setActive(false) notification to pid 17984 uid 10050

答案我想你需要修改getValue(),如下所示。该方法的参数element应该是成员节点。调用getElementsByTagName()将返回后代,后代应该是您要解析的标记。调用getChildNodes()试图找到那些不存在的标记内的标记。
相反,element.getElementsByTagName(tag).item(0)应返回与您要查找的标记匹配的节点。
private static String getValue(String tag, Element element) { Node node = element.getElementsByTagName(tag).item(0); return node.getNodeValue(); }

此外,请注意,根据Node的文档,getValue()仍然可以为< username/> (来自您的示例x??ml)等项目返回null。
【在Android中登录尝试失败时app崩溃了】https://developer.android.com/reference/org/w3c/dom/Node.html

    推荐阅读