我正在摆弄 MonoDroid(又名 Mono for Android),试图构建一个简单的播客下载应用程序,目前只是测试对 RSS 提要内容的检索。
我的简单应用是:
- 输入 RSS 提要的 url 的编辑文本
- 一个“下载”RSS的按钮
- 下载操作输出的文本显示
当用户单击下载时,我会获取当前使用的 RSS 内容(我也XDocument
尝试过使用/ s 等),这是简短版本:WebRequest
Stream
void button_Click(object sender, EventArgs e)
{
output.Text += "user input: " + rssUriInput.Text + "\n";
try
{
output.Text += "### document ###";
output.Text += XDocument.Load(rssUriInput.Text).ToString();
output.Text += "### document ###";
}
catch (Exception ex)
{
output.Text += "OOOPS something went wrong:\n" + ex.ToString();
}
}
我已经尝试了几种方法,但是ObjectDisposedException
当我这样做时不断得到 sXDocument.Load(/*my uri here*/);
我的 AssemblyInfo.cs 包括
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
现在,免责声明,在运行 hello world 之后,我有点自己跑了,所以我可能缺少一些 MonoDroid 基础知识,但是这段代码在普通的 C# 应用程序中工作(我测试过)但是
为什么我在这里做错了?我必须做一些特别的事情才能在 MonoDroid 中使用 xml / linq / 网络访问吗?
这是完整的活动代码:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.Xml.Linq;
namespace RssDownlowd
{
[Activity(Label = "RssDownlowd", MainLauncher = true, Icon = "@drawable/icon")]
public class Activity1 : Activity
{
EditText rssUriInput;
Button button;
TextView output;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.RssDownload);
rssUriInput = FindViewById<EditText>(Resource.Id.rssUriText);
button = FindViewById<Button>(Resource.Id.downloadButton);
output = FindViewById<TextView>(Resource.Id.outputTextView);
button.Click += new EventHandler(button_Click);
}
void button_Click(object sender, EventArgs e)
{
output.Text += "user input: " + rssUriInput.Text + "\n";
try
{
output.Text += "### document ###";
output.Text += XDocument.Load(rssUriInput.Text).ToString();
output.Text += "### document ###";
}
catch (Exception ex)
{
output.Text += "OOOPS something went wrong:\n" + ex.ToString();
}
}
}
}
这是完整的例外:
"System.ObjectDisposedException: The object was used after being disposed.
at System.Net.WebConnection.BeginRead (System.Net.HttpWebRequest request, System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x00000] in <filename unknown>:0
at System.Net.WebConnectionStream.BeginRead (System.Byte[] buffer, Int32 offset, Int32 size, System.AsyncCallback cb, System.Object state) [0x00000] in <filename unknown>:0
at System.Net.WebConnectionStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00000] in <filename unknown>:0
at System.Xml.XmlInputStream.Read (System.Byte[] buffer, Int32 offset, Int32 count) [0x00000] in <filename unknown>:0
at System.Xml.NonBlockingStreamReader.ReadBuffer () [0x00000] in <filename unknown>:0
at System.Xml.NonBlockingStreamReader.Read (System.Char[] dest_buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0
at System.Xml.XmlStreamReader.Read (System.Char[] dest_buffer, Int32 index, Int32 count) [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.ReadTextReader (Int32 remained) [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.PeekChar () [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.ReadChar () [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.Expect (Int32 expected) [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.ReadEntityReference (Boolean ignoreEntityReferences) [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.ReadReference (Boolean ignoreEntityReferences) [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.ReadText (Boolean notWhitespace) [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.ReadContent () [0x00000] in <filename unknown>:0
at Mono.Xml2.XmlTextReader.Read () [0x00000] in <filename unknown>:0
at System.Xml.XmlTextReader.Read () [0x00000] in <filename unknown>:0
at Mono.Xml.XmlFilterReader.Read () [0x00000] in <filename unknown>:0
at System.Xml.Linq.XElement.LoadCore (System.Xml.XmlReader r, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XNode.ReadFrom (System.Xml.XmlReader r, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XElement.LoadCore (System.Xml.XmlReader r, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XNode.ReadFrom (System.Xml.XmlReader r, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XElement.LoadCore (System.Xml.XmlReader r, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XNode.ReadFrom (System.Xml.XmlReader r, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XElement.LoadCore (System.Xml.XmlReader r, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XNode.ReadFrom (System.Xml.XmlReader r, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XContainer.ReadContentFrom (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XDocument.ReadContent (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XDocument.LoadCore (System.Xml.XmlReader reader, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XDocument.Load (System.String uri, LoadOptions options) [0x00000] in <filename unknown>:0
at System.Xml.Linq.XDocument.Load (System.String uri) [0x00000] in <filename unknown>:0
at RssDownlowd.Activity1.button_Click (System.Object sender, System.EventArgs e) [0x0004a] in C:\\Users\\khd483\\code\\HelloMonoDroid\\RssDownlowd\\Activity1.cs:47 "