Resources.Load in static class

i’m trying to load a XML

public static class selIdioma
{ 
static XmlDocument xDoc; 
public static void cargarIdioma() 
{ 
string name=preferencias.pref.idioma; 
TextAsset textAsset=(TextAsset)Resources.Load(name); 
xDoc.LoadXml(textAsset.text); 
}
}

Name without extension. I’ve folder Resources into Assets. But it shows me this message

Why?
(I’m sorry for my english)

Which reference is null?

Line 9, although when arrives textAsset is null

According to the docs this will occur if the asset is not found at the specified path. Check the path is correct.

I have tried

TextAsset textAsset = (TextAsset) Resources.Load(Application.dataPath +"/Resources/"+name);
TextAsset textAsset = (TextAsset) Resources.Load(name);
TextAsset textAsset = (TextAsset) Resources.Load("/Resources/"+name);
TextAsset textAsset = (TextAsset) Resources.Load("Resources/"+name);

Name with extension and without extension.
I do not know if i need to reference assets folder
The path is Assets/Resources/archivo.xml

The path is relative to the resources folder. So there is no need to include Resources. Just the name should be enough. Assuming you have the correct name?

Yes, the name is correct, i rename it to 1.xml and 0.xml.
Could be for the static class ?

No. Static has nothing to do with this.

Resources.Load is simply not finding an asset in the Resources folder with the appropriate name.

it should find them

I’d be guessing that static XmlDocument xDoc; is null, it’s never been assigned.

Change line 4 to:

static XmlDocument xDoc = new XmlDocument();

3 Likes

This.

Teach me for believing the OP. :wink:

1 Like

It worked, thank you very much.

1 Like