Xamarin-Android.Util.AndroidRuntimeException:<超时超过了获取异常详细信息>

时间:2019-07-17 12:40:59

标签: c# xaml xamarin xamarin.forms

我不断收到此错误:

allTokensAvailable for Thread-3 true/false

它来自以下行:

Unhandled Exception:

Android.Util.AndroidRuntimeException: <Timeout exceeded getting exception 
details>

这是我使用的代码:

lbl_geheel.Text += node.InnerText;

这是使用HTMLAgility包抓取数据的代码。

这是XAML中的标签:

public string url = "https://www.xscores.com/tennis/livescores/livegames";

    public MainPage()
    {
        InitializeComponent();

        Thread t = new Thread(() => Start());
        t.Start();
    }

    public void Start()
    {
        string source = getSource(url);
        if (source == "") return;

        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
        doc.LoadHtml(source);

        HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@class='score_ht score_cell centerTXT']");

        foreach  (HtmlNode node in nodes)
        {
            lbl_geheel.Text += node.InnerText;
        }
    }

    string getSource(string url)
    {
        try
        {
            WebClient myWebClient = new WebClient();
            myWebClient.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            byte[] myDataBuffer = myWebClient.DownloadData(url);
            string source = Encoding.ASCII.GetString(myDataBuffer);

            return source;
        }
        catch(Exception ex)
        {
            return "";
        }
    }

我在<Label x:Name="lbl_geheel" Text="Hier komt de gehele sectie" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" /> 处设置了一个断点,并且它返回null。那怎么可能?我已经在XAML中设置了文本,对吗?启动应用程序时,我首先看到错误而不是文本。这是否意味着lbl_geheel.Text += node.InnerText;在加载UI之前运行?我该如何预防?

0 个答案:

没有答案