Siames
December 7, 2016, 12:10am
1
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)
Siames
December 7, 2016, 1:20am
3
Line 9, although when arrives textAsset is null
Kiwasi
December 7, 2016, 2:21am
4
According to the docs this will occur if the asset is not found at the specified path. Check the path is correct.
Siames
December 7, 2016, 2:41am
5
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
Kiwasi
December 7, 2016, 3:02am
6
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?
Siames
December 7, 2016, 3:55am
7
Yes, the name is correct, i rename it to 1.xml and 0.xml.
Could be for the static class ?
Kiwasi
December 7, 2016, 4:02am
8
No. Static has nothing to do with this.
Resources.Load is simply not finding an asset in the Resources folder with the appropriate name.
larku
December 7, 2016, 4:11am
10
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
Kiwasi
December 7, 2016, 4:23am
11
larku:
I’d be guessing that static XmlDocument xDoc; is null, it’s never been assigned.
Change line 4 to:
static XmlDocument xDoc = new XmlDocument();
This.
Teach me for believing the OP.
1 Like
Siames
December 9, 2016, 3:27pm
12
It worked, thank you very much.
1 Like