Почему SAX-парсер не работает на телефоне, но работает на эмуляторе? - PullRequest
0 голосов
/ 11 января 2012

Я получаю следующую ошибку при запуске приложения на телефоне, но при работе в эмуляторе.

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);
    }

01-11 12: 47: 15.194: W / System.err (7300): org.apache.harmony.xml.ExpatParser $ ParseException: в строке 20, столбец 76: неправильно сформирован (неверный токен) 01-11 12: 47: 15.194: W / System.err (7300): at org.apache.harmony.xml.ExpatParser.parseFragment (ExpatParser.java:523) 01-11 12: 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): в org.apache.harmony.xml.ExpatReader.parse (ExpatReader.java:320) 01-11 12: 47: 15.204: W / System.err (7300): at org.apache.harmony.xml.ExpatReader.parse (ExpatReader.java:277) 01-11 12: 47: 15.204: W / System.err (7300): at com.apps.clx.bouncemein.WelcomeActivity.tryLogin(WelcomeActivity.java:258) 01-11 12: 47: 15.204: W / System.err (7300): на com.apps.clx.bouncemein.WelcomeActivity $ 6.run (WelcomeActivity.java:161) 01-11 12:47: 15.204: W / System.err (7300): на android.app.Activity.runOnUiThread (Activity.java:3707) 01-11 12: 47: 15.204: W / System.err (7300): на com.apps.clx.bouncemein.WelcomeActivity.loadDataInView (WelcomeActivity.java:156) 01-11 12:47: 15.204: W / System.err (7300): по адресу com.apps.clx.bouncemein.WelcomeActivity.access $ 1 (WelcomeActivity.java:152) 01-11 12: 47: 15.204: W / System.err (7300): в com.apps.clx.bouncemein.WelcomeActivity $ 3.onClick (WelcomeActivity.java:84) 01-11 12: 47: 15.204: W / System.err (7300): в android.view.View.performClick (Просмотреть.Java: 2408) 01-11 12: 47: 15.214: W / System.err (7300): at android.view.View $ PerformClick.run (View.java:8816) 01-11 12: 47: 15.214: W /System.err (7300): на android.os.Handler.handleCallback (Handler.java:587) 01-11 12: 47: 15.214: W / System.err (7300): на android.os.Handler.dispatchMessage (обработчик.java: 92) 01-11 12: 47: 15.214: W / System.err (7300): at 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): на com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:858)

, пожалуйста, помогите мне.

iполучаю следующую ошибку, пожалуйста, проверьте ее и дайте мне знать.

<code>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;
01-11 16: 09: 42.425: I / System.out (11616): 01-11 16: 09: 42.425: I / System.out (11616): 01-11 16: 09: 42.425: I / System.out (11616): 01-11 16: 09: 42.425: I / System.out (11616)):
01-11 16: 09: 42.425: I / System.out (11616): Примечания: Текущая страница ошибки, которую вы видите, может быть заменена пользовательской страницей ошибок, изменив "defaultRedirect "атрибут тега конфигурации приложения для указания URL-адреса пользовательской страницы ошибки.

01-11 16: 09: 42.425: I / System.out (11616):01-11 16: 09: 42.425: I / System.out (11616): 01-11 16: 09: 42.425: I / System.out (11616): 01-11 16: 09: 42.425: I / System.out (11616): 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; 01-11 16: 09: 42.425: I / System.out (11616): 01-11 16: 09: 42.425: I / System.out (11616)): 01-11 16: 09: 42,425: I / System.out (11616): 01-11 16: 09: 42,425: I / System.out (11616):
01-1116: 09: 42.425: I / System.out (11616): 01-11 16: 09: 42.425: I / System.out (11616): 01-11 16: 09: 42.445: I /System.out (11616): внутри диалогового окна

Ответы [ 2 ]

0 голосов
/ 11 января 2012

Не правильно сформированный (неверный токен), как правило, приводящий к неправильному XML-ответу, проверьте строку XML-ответа следующим способом:

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

и проверьте, имеет ли эта строка какой-либо специальный символ (например, '&') init.если есть, замените эти символы.

0 голосов
/ 11 января 2012

Ошибка указывает, что что-то не так с вашим XML.

Во-первых, вы должны проверить, что вы получаете правильный ответ из сети.Посмотрите на http ответ код состояния :

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 здесь?

...