2

私は MonoDroid (別名 Mono for Android) をいじって、単純なポッドキャスト ダウンロード アプリを構築しようとしています。現在、RSS フィード コンテンツの取得をテストしています。

私のシンプルなアプリは次のとおりです。

  • RSS フィードの URL を入力する編集テキスト
  • RSS を「ダウンロード」するボタン
  • ダウンロード操作の出力のテキスト表示

ユーザーがダウンロードをクリックすると、現在使用している RSS コンテンツを取得します( / s などXDocumentでも試しましWebRequestStream)。短いバージョンは次のとおりです。

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私がやるとsを得続けますXDocument.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 "
4

1 に答える 1

1

Strangely enough when I tried your code it worked just fine:

Screen shot

Have you enabled Linking in your project in the Mono for Android options?

Also consider doing an async download of the RSS as it blocks the UI Thread until it is done, making the app unresponsive.

于 2012-05-31T09:39:32.617 に答える