0

我需要在我的 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>
4

1 回答 1

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

注意::不要忘记在您的清单文件中添加所需的权限。

于 2012-04-26T16:39:00.820 回答