Note that there are some explanatory texts on larger screens.

plurals
  1. POEquality nonsense in Android
    text
    copied!<p>The problem is that I expect the text that I read from a webpage calling <code>grabURL</code> is absolutely equal to what I put into <code>String lorem</code> in the <code>onPostExecute</code>.</p> <p>But Android says: "No, it does not!" </p> <p>Why do I think Android is not right about equality?</p> <p>1) StackTrace screenshot:</p> <p><img src="https://i.stack.imgur.com/cuGri.jpg" alt="STACKTRACE"></p> <p>2) Screenphoto:</p> <p><img src="https://i.stack.imgur.com/YIGvl.jpg" alt="NOT EQUAL"></p> <p>3) You can find <code>String lorem = "Lorem ipsum dolor sit amet";</code> downward in my class, and look through the source code of the webpage I'm reading text from:</p> <p><img src="https://i.stack.imgur.com/FrIOi.jpg" alt="SOURCE CODE"></p> <p>Source code of my classes:</p> <pre><code>public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); grabURL("http://www.cyberweb.pp.ua/x/o.html"); } public void grabURL(String url) { new GrabURL().execute(url); } private class GrabURL extends AsyncTask&lt;String, Void, Void&gt; { private final HttpClient Client = new DefaultHttpClient(); private String Content; private String Error = null; protected Void doInBackground(String... urls) { try { HttpGet httpget = new HttpGet(urls[0]); ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); Content = Client.execute(httpget, responseHandler); } catch (ClientProtocolException e) { Error = e.getMessage(); cancel(true); } catch (IOException e) { Error = e.getMessage(); cancel(true); } return null; } protected void onPostExecute(Void unused) { String lorem = "Lorem ipsum dolor sit amet"; if (Error != null) { Toast.makeText(MainActivity.this, Error, Toast.LENGTH_LONG) .show(); } else { TextView xyu = (TextView) findViewById(R.id.xyu); TextView xyu1 = (TextView) findViewById(R.id.xyu1); TextView xyu2 = (TextView) findViewById(R.id.xyu2); xyu.setText(Content); xyu1.setText(lorem); Log.v("lorem", lorem); Log.v("Content", Content); String eq = null; if (Content.length() != lorem.length()) { Log.v("length?", "Different length"); } if (Content.trim().equalsIgnoreCase(lorem.trim())) { xyu2.setText("EQUAL"); eq = "EQUAL"; Log.v("equal?", eq); } else { xyu2.setText("NOT EQUAL"); eq = "NOT EQUAL"; Log.v("equal?", eq); } } } } } </code></pre> <p>This issue is driving me nuts. </p> <p>Сan anybody guess what happens? Thank you in advance!</p> <p>Last Stacktrace:</p> <p><img src="https://i.stack.imgur.com/fjH3g.jpg" alt="enter image description here"></p> <p><strong>The issue was caused by webpage encoding. Equality is correct when changing the encoding to</strong> <code>UTF-8</code>. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload