简体   繁体   English

Android:加载URL时WebView显示空白页

[英]Android: WebView show blank page when loading url

I did an Android app that is basically a WebView that loads a url using loadUrl . 我做了一个Android应用程序,它基本上是一个WebView ,它使用loadUrl加载URL。
The problem I have is that when in the app navigation some links the webview says "page not found" but links are ok if you go in a browser. 我的问题是,在应用程序导航中,某些链接在Web视图中显示“找不到页面”,但是如果您使用浏览器,则链接可以。

Edition: It is not the character the problem I can not determine yet a patron in links that yelds to the error. 版本:不是字符,我仍然无法确定问题的赞助者,这是导致错误的原因。 I only see the mensaje "page finished loading" twice on pages that throws error. 我在抛出错误的页面上只看到两次Mensaje“页面加载完成”。

I tried to catch the moment when the url loads but I do not know how to solve this problem. 我试图赶上URL加载的那一刻,但我不知道如何解决此问题。 It only happens on links that are like: http://host/about-us 它仅在以下链接上发生: http:// host / about-us

This is my code of the part that catches the problematic links 这是我捕获问题链接的那部分代码

public boolean shouldOverrideUrlLoading(WebView view, String url) {
    Log.i(TAG, "Processing webview url click...");
    if (url.contains("-")) {
        // magic
        Log.i(TAG, "Url contains - ...");
        view.loadUrl(url);
        return false;
    }
    view.loadUrl(url);
    return false;
}

I got "Url contains - ..." on the logs but I do not know how to get the page open. 我在日志中看到“ URL包含-...”,但我不知道如何打开页面。
If I visit the links on the browser they work perfectly and there is nothing wrong about the urls. 如果我在浏览器上访问链接,它们将正常工作,并且URL没有错。

Thanks a lot if anybody can give me a clue of what is going on, I tried many searches before asking. 非常感谢任何人都能给我一个线索,在询问之前我尝试了很多次搜索。

Resolved: It was missing Internet Permission on manifiest file: 解决:在manifiedt文件上缺少Internet许可:

I did not realize that everytime I compilate the app and install on my phone the cache remains. 我没有意识到,每次编译应用程序并将其安装在手机上时,都会保留缓存。 The pages I was seeing were in app cache. 我看到的页面在应用程序缓存中。 What I do not know is how the lines that gives internet permission disappear from my manifiest. 我不知道的是,提供互联网许可的线路是如何从我的男人消失的。 I use Eclipse IDE do not know if there is a way eclipse overwrites this files. 我使用Eclipse IDE不知道eclipse是否有一种方法可以覆盖此文件。 Thanks for the hints 谢谢你的提示

Please try to use the following to code to check what the error is. 请尝试使用以下代码来检查错误是什么。

 webview.setWebViewClient(new WebViewClient() {
   public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
     Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
   }
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM