问题是我希望我从网页调用grabURL
中读取的文本绝对等于我String lorem
在onPostExecute
.
但安卓说:“不,它没有!”
为什么我认为 Android 在平等方面不正确?
1)堆栈跟踪截图:
2) 截图:
3)您可以String lorem = "Lorem ipsum dolor sit amet";
在我的课堂上找到向下,并查看我正在阅读的网页的源代码:
我的课程的源代码:
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<String, Void, Void> {
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<String> 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);
}
}
}
}
}
这个问题快把我逼疯了。
Сan有人猜会发生什么?先感谢您!
最后的堆栈跟踪:
该问题是由网页编码引起的。将编码更改为 时,相等是正确的 UTF-8
。