2012-01-11 76 views
-1

我在手机上运行应用程序时遇到以下错误,但在仿真器上工作。为什么SAX解析器不能在手机上工作,但在模拟器上工作?

HttpClient client = new DefaultHttpClient(); 
    HttpPost httppost = new HttpPost(BMIConstant.Url + "ValidLoginUser"); 
    List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>(); 
    password = etxt_pass.getText().toString().trim(); 
    username = etxt_user.getText().toString().trim(); 
    nvps.add(new BasicNameValuePair("Emailaddress", username)); 
    nvps.add(new BasicNameValuePair("Password", password)); 
    System.out.println("user name is--->"+username+ " password---->"+password); 
    System.out.println(httppost.getRequestLine()); 

    try { 
     UrlEncodedFormEntity p_entity = new UrlEncodedFormEntity(nvps, HTTP.UTF_8); 
     httppost.setEntity(p_entity); 
     HttpResponse response = client.execute(httppost); 
     HttpEntity responseEntity = response.getEntity();   
     SAXParserFactory spf = SAXParserFactory.newInstance(); 
     SAXParser sp = spf.newSAXParser(); 
     XMLReader xr = sp.getXMLReader(); 
     LoginHandler myLoginHandler = new LoginHandler(); 
     xr.setContentHandler(myLoginHandler); 
     xr.parse(new InputSource(responseEntity.getContent())); 
     LoginParser myLoginParser = myLoginHandler.parser; 
     System.out.println("return code is---->"+myLoginParser.getCode()); 

     id = Integer.parseInt(myLoginParser.getCode()); 

    } catch (Exception e) { 
     e.printStackTrace(); 

     removeDialog(0); 
    } 

12月1日至11日:47:15.194:W/System.err的(7300):org.apache.harmony.xml.ExpatParser $ ParseException的:在第20行,列76:没有很好地形成(无效令牌) 十二月1日至11日:47:15.194:W/System.err的(7300):在org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:523) 十二月1日至11日:47:15.194: W/System.err(7300):at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:482) 01-11 12:47:15.194:W/System.err(7300):at org。 apache.harmony.xml.ExpatReader.parse(ExpatReader.java:320) 12月1日至11日:47:15.204:W/System.err的(7300):在org.apache.harmony.xml.ExpatReader.parse(ExpatReader。 java:277) 01-11 12:47:15.204:W/System.err(73 00):at com.apps.clx.bouncemein.WelcomeActivity.tryLogin(WelcomeActivity.java:258) 01-11 12:47:15.204:W/System.err(7300):at com.apps.clx.bouncemein。 WelcomeActivity $ 6.run(WelcomeActivity.java:161) 十二月1日至11日:47:15.204:W/System.err的(7300):在android.app.Activity.runOnUiThread(Activity.java:3707) 十二月1日至11日:47:15.204:W/System.err(7300):at com.apps.clx.bouncemein.WelcomeActivity.loadDataInView(WelcomeActivity.java:156) 01-11 12:47:15.204:W/System.err(7300 ):at com.apps.clx.bouncemein.WelcomeActivity.access $ 1(WelcomeActivity.java:152) 01-11 12:47:15.204:W/System.err(7300):at com.apps.clx.bouncemein。 WelcomeActivity $ 3.onClick(WelcomeActivity.java:84) 12月1日至11日:47:15.204:W/System.err的(7300):在android.view.View.performClick(View.java:2408) 12月1日至11日:47:15.214:W/S ystem.err(7300):at android.view.View $ PerformClick.run(View.java:8816) 01-11 12:47:15.214:W/System.err(7300):at android.os.Handler。 handleCallback(Handler.java:587) 01-11 12:47:15.214:W/System.err的(7300):在android.os.Handler.dispatchMessage(Handler.java:92) 01-11 12点47: 15.214:W/System.err(7300):在android.os.Looper.loop(Looper.java:123) 01-11 12:47:15.214:W/System.err(7300):在android.app。 ActivityThread.main(ActivityThread.java:4633) 01-11 12:47:15.214:W/System.err的(7300):在java.lang.reflect.Method.invokeNative(本机方法) 01-11 12点47 :15.214:W/System.err(7300):at java.lang.reflect.Method.invoke(Method.java:521) 01-11 12:47:15.214:W/System.err(7300):at com .android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:858)

请帮帮我。

我收到以下错误请检查它并让我知道。

I/System.out(11616): result is:<html> 
    01-11 16:09:42.415: I/System.out(11616):  <head> 
    01-11 16:09:42.415: I/System.out(11616):   <title>Runtime Error</title> 
    01-11 16:09:42.415: I/System.out(11616):   <style> 
    01-11 16:09:42.415: I/System.out(11616):   body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
    01-11 16:09:42.415: I/System.out(11616):   p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} 
    01-11 16:09:42.415: I/System.out(11616):   b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} 
    01-11 16:09:42.415: I/System.out(11616):   H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } 
    01-11 16:09:42.415: I/System.out(11616):   H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } 
    01-11 16:09:42.415: I/System.out(11616):   pre {font-family:"Lucida Console";font-size: .9em} 
    01-11 16:09:42.425: I/System.out(11616):   .marker {font-weight: bold; color: black;text-decoration: none;} 
    01-11 16:09:42.425: I/System.out(11616):   .version {color: gray;} 
    01-11 16:09:42.425: I/System.out(11616):   .error {margin-bottom: 10px;} 
    01-11 16:09:42.425: I/System.out(11616):   .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } 
    01-11 16:09:42.425: I/System.out(11616):   </style> 
    01-11 16:09:42.425: I/System.out(11616):  </head> 
    01-11 16:09:42.425: I/System.out(11616):  <body bgcolor="white"> 
    01-11 16:09:42.425: I/System.out(11616):    <span><H1>Server Error in '/BounceMeInWS' Application.<hr width=100% size=1 color=silver></H1> 
    01-11 16:09:42.425: I/System.out(11616):    <h2> <i>Runtime Error</i> </h2></span> 
    01-11 16:09:42.425: I/System.out(11616):    <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> 
    01-11 16:09:42.425: I/System.out(11616):    <b> Description: </b>An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 
    01-11 16:09:42.425: I/System.out(11616):    <br><br> 
    01-11 16:09:42.425: I/System.out(11616):    <b>Details:</b> To enable the details of this specific error message to be viewable on remote machines, please create a &lt;customErrors&gt; tag within a &quot;web.config&quot; configuration file located in the root directory of the current web application. This &lt;customErrors&gt; tag should then have its &quot;mode&quot; attribute set to &quot;Off&quot;.<br><br> 
    01-11 16:09:42.425: I/System.out(11616):    <table width=100% bgcolor="#ffffcc"> 
    01-11 16:09:42.425: I/System.out(11616):    <tr> 
    01-11 16:09:42.425: I/System.out(11616):     <td> 
    01-11 16:09:42.425: I/System.out(11616):      <code><pre> 
    01-11 16:09:42.425: I/System.out(11616): &lt;!-- Web.Config Configuration File --&gt; 
    01-11 16:09:42.425: I/System.out(11616): &lt;configuration&gt; 
    01-11 16:09:42.425: I/System.out(11616):  &lt;system.web&gt; 
    01-11 16:09:42.425: I/System.out(11616):   &lt;customErrors mode=&quot;Off&quot;/&gt; 
    01-11 16:09:42.425: I/System.out(11616):  &lt;/system.web&gt; 
    01-11 16:09:42.425: I/System.out(11616): &lt;/configuration&gt;</pre></code> 
    01-11 16:09:42.425: I/System.out(11616):     </td> 
    01-11 16:09:42.425: I/System.out(11616):    </tr> 
    01-11 16:09:42.425: I/System.out(11616):    </table> 
    01-11 16:09:42.425: I/System.out(11616):    <br> 
    01-11 16:09:42.425: I/System.out(11616):    <b>Notes:</b> The current error page you are seeing can be replaced by a custom error page by modifying the &quot;defaultRedirect&quot; attribute of the application&#39;s &lt;customErrors&gt; configuration tag to point to a custom error page URL.<br><br> 
    01-11 16:09:42.425: I/System.out(11616):    <table width=100% bgcolor="#ffffcc"> 
    01-11 16:09:42.425: I/System.out(11616):    <tr> 
    01-11 16:09:42.425: I/System.out(11616):     <td> 
    01-11 16:09:42.425: I/System.out(11616):      <code><pre> 
    01-11 16:09:42.425: I/System.out(11616): &lt;!-- Web.Config Configuration File --&gt; 
    01-11 16:09:42.425: I/System.out(11616): &lt;configuration&gt; 
    01-11 16:09:42.425: I/System.out(11616):  &lt;system.web&gt; 
    01-11 16:09:42.425: I/System.out(11616):   &lt;customErrors mode=&quot;RemoteOnly&quot; defaultRedirect=&quot;mycustompage.htm&quot;/&gt; 
    01-11 16:09:42.425: I/System.out(11616):  &lt;/system.web&gt; 
    01-11 16:09:42.425: I/System.out(11616): &lt;/configuration&gt;</pre></code> 
    01-11 16:09:42.425: I/System.out(11616):     </td> 
    01-11 16:09:42.425: I/System.out(11616):    </tr> 
    01-11 16:09:42.425: I/System.out(11616):    </table> 
    01-11 16:09:42.425: I/System.out(11616):    <br> 
    01-11 16:09:42.425: I/System.out(11616):  </body> 
    01-11 16:09:42.425: I/System.out(11616): </html> 
    01-11 16:09:42.445: I/System.out(11616): inside dialoge box 
+0

你能打印'responseEntity'的内容(使用'EntityUtils.toString(HttpEntity)')并附加到你的问题吗? – Jens 2012-01-11 08:37:19

+0

我已添加responseEntity的内容检查它。 – user1142637 2012-01-11 11:35:51

+0

嗯,这个问题不在你的android代码中 - 你的web服务崩溃了。你最好去检查服务器日志。 – Jens 2012-01-11 11:44:35

回答

0

错误表明您的XML存在问题。

首先,您应该检查您是否从网络获得了正确的答复。查看HTTP响应status code

if(response.getStatusLine().getStatusCode() == 200){ 
    // it's ok, proceed with parsing 
} else { 
    // som error: retry, notify user, etc.. 
} 

我的猜测是,你正在试图访问localhost(= 127.0.0.1)。改为使用10.0.2.2

更新: 错误的地址或端口将产生一个异常没有错误的响应代码。 XML一定有一些问题。也许是编码问题?你能在这里发布有问题的XML吗?

+0

连接到例如无响应主机(例如本地主机),或者错误的端口给你一个例外,而不是HTTP状态码。 – Jens 2012-01-11 08:36:07

+0

是真的,将更正答案 – 2012-01-11 08:38:52

0

没有很好地形成(无效令牌)通常导致一个坏响应XML,通过以下方法检查响应XML字符串:

HttpEntity responseEntity = response.getEntity();
String responseString = EntityUtils.convertStreamtoString(responseEntity);

并检查此字符串是否有任何特殊字符(例如'&')init。如果有,请替换这些字符。

+0

谢谢,我从设备上的Web服务获取数据时发生服务器错误,但我能够在模拟器上成功获取数据。 – user1142637 2012-01-11 11:28:45

+0

ok,那么你需要检查你是否需要在服务器端应用程序上有一些不接受设备端连接的特定设置,或者当你通过设备访问webservice时需要发送一些特殊参数给服务器,你可以访问代理模拟器/代理设备对面的网络。 – jeet 2012-01-11 11:33:46

相关问题