Forum Cross Platform with Xamarin

Why im getting this error?

msa3edyaqoubmsa3edyaqoub USMember ✭✭

hello everyone
I'm trying to build my first project in xamarin
and getting this error I don't know why

my code is simple

I'm just trying to retrieve data from xml file in android assets folder

so i made xaml search page with search button and entry

    public void SrchBtn(object sender , EventArgs e)
        Myproject.Droid.MainActivity mainActivity = new Myproject.Droid.MainActivity();
        List<string> result = new List<string>();
        result = mainActivity.searchMethod(SrchText.Text);

and then I make this searchMethod in MainActivity.cs

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

string text1;

    public List<string> resultList = new List<string>();

public List searchMethod(string wordContain)

        XmlReader xmlReader = XmlReader.Create(Assets.Open("Data.xml"));

        while (xmlReader.Read())

            if (xmlReader.HasAttributes)

                text1 = xmlReader.GetAttribute("text");

                if (!string.IsNullOrEmpty(text1) && text1.Contains(wordContain))




        return resultList;

I got error with this first code
XmlReader xmlReader = XmlReader.Create(Assets.Open("Data.xml"));
Java.Lang.NullPointerException Timeout exceeded getting exception

I've tried the whole code in windows console app and it works fine
also XmlReader work fine and can read the file only if its outside searchMethod
any suggestion????

thank you


  • MommMomm USMember ✭✭✭
    edited August 2017

    @msa3edyaqoub Please try to read from "file:///android_asset/Data.xml".

    Also, have you set this asset's bundle action to AndroidAsset?

    Let me know if it helps you.

  • msa3edyaqoubmsa3edyaqoub USMember ✭✭

    thank for your reply Momm

    fortunately ive solved the problem
    it turns out I was doing it all wrong !
    I shouldn't even use assets for storing data xml in my shared project !
    ive read this tutorial before posting here

    it turns out I was doing a small mistake of typing "myproject.PCLTextResource.txt" while it should be "myproject.Droid.PCLTextResource.txt"
    so here is the full code so others may benefit :)

    if IOS

        string resourcePrefix = "myproject.iOS.";


    if ANDROID

            string resourcePrefix = "myproject.Droid.";


    var assembly = typeof(Search).GetTypeInfo().Assembly;
    Stream stream = assembly.GetManifestResourceStream(resourcePrefix + "data.xml");
    XElement xelement = XElement.Load(stream);

    now I'm getting new damn errors !
    a lot of errors!

    and I really suspect its hardware failure this time !
    its unbelievable
    my solution build just fine and 1 munite later
    errors appears !
    build succeed
    and then
    errors appears !
    and so on with out even changing anything !
    when doing a shut down no errors appears and i can deploy my solution to phone
    now those stinky errors wont go away

    AND new error just came up !

    Xamarin.Android for Visual Studio requires Android SDK.
    Please install it or set Android SDK path on Tools->Options->Xamarin->Android Settings menu

    not only that
    i notes now my pc is running much smother and faster !
    weird isn't it ?
    my pc was in dust for long time and when i turned it on it was the king of errors!
    give me errors of every software i use!

    after cleaning it + replacing ram positions + format
    all the problems fixed
    except now xamarain isnt working and i suspect its might be some hardware failure
    could it be ? what do you guys think could it be from hardware failure ?
    i really wants xamarain to work it just so beautiful and i made a lot of progress in my project

  • msa3edyaqoubmsa3edyaqoub USMember ✭✭

    after doing a lot hardware diagnostic all result was fine

    now after doing a repair with visual studio the android SDK error disappeared

    linq error also resolved by deleting those references and re add them again


    thank you !

  • msa3edyaqoubmsa3edyaqoub USMember ✭✭

    Hmmm so some admin deleted my previous post
    any way I updating with new errors which all resolved now
    thank you :)

  • msa3edyaqoubmsa3edyaqoub USMember ✭✭
    edited August 2017


  • msa3edyaqoubmsa3edyaqoub USMember ✭✭
    edited August 2017


  • msa3edyaqoubmsa3edyaqoub USMember ✭✭
    edited August 2017


  • msa3edyaqoubmsa3edyaqoub USMember ✭✭
    edited August 2017


Sign In or Register to comment.