我需要在我的Android应用中显示Webview。问题是我试图显示的网页出错:
"This page contains the following errors:
error on line xxx at column xxx: Entity 'abc' is not defined
Below is the rendering of the page upto the first error"
该网站在我的移动浏览器和桌面上都能正常运行。此外,我不会在其他网站上收到此错误
无论如何,我可以避免这个错误。请帮助。
这是java代码:
public class Zero extends Activity {
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.zero);
wv=(WebView) findViewById(R.id.web);
wv.getSettings().setJavaScriptEnabled(true);
//wv.loadUrl("http://customercare.indianrailways.gov.in/criscm/common/complaint_registration.seam");
wv.loadUrl("http://ndtv.com");
wv.setWebViewClient(new HelloWebViewClient());
final Activity activity = this;
wv.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle("Easy Complaint Indian Railways");
}
});
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && wv.canGoBack()) {
wv.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
布局xml文件:
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/web">
</WebView>
答案 0 :(得分:0)
使用以下活动加载您的网址:::
public class WebViewsScreenActivity extends Activity {
private WebView mwebview;
private WebViewsScreenActivity _activity;
ProgressDialog _dilog;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.webview);
_activity = this;
mwebview=(WebView)findViewById(R.id.webview);
mwebview.getSettings().setJavaScriptEnabled(true);
mwebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
if(checkInternetConnection(_activity)){
if(savedInstanceState==null)
mwebview.loadUrl(webUrl);
else
mwebview.restoreState(savedInstanceState);
}
else{
//showAlert "Unable to Connect Server"
}
mwebview.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
if(mwebview.getVisibility()==View.VISIBLE)
{
WebViewsScreenActivity .this.setProgress(progress * 100);
}
}
});
mwebview.setWebViewClient(new HelloWebViewClient());
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_BACK)
{
mwebview.goBack();
return true;
}
else
return super.onKeyUp(keyCode, event);
}
//To check whether network connection is available on device or not
private boolean checkInternetConnection(Activity _activity) {
ConnectivityManager conMgr = (ConnectivityManager) _activity.getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected())
return true;
else
return false;
}//checkInternetConnection()
//HelloWebViewClient class for webview
private class HelloWebViewClient extends WebViewClient {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
} //HelloWebViewClient-class
}//AccountsScreenActivity-class
注意::不要忘记在展示文件中添加所需的权限。