Hello, i use this function:
public void Elements_LoadAll(List<string> allElementsList)
{
if (allElementsList == null)
{
allElementsList = new List<string>();
}
foreach (string key in ES3.GetKeys("Elements.es3"))
{
if (!allElementsList.Contains(key))
allElementsList.Add(key);
}
}
And if there are no elements in the file "Elements.es3" i get a null reference error. Could i add a check to not avoid the error?
GetKeys Gives a null reference error
Re: GetKeys Gives a null reference error
Hi there,
I don't appear to be getting a null reference exception from ES3.GetKeys on a file with no keys. I've tested this with the following code in the latest version:
It will throw a FileNotFoundException if the file doesn't exist but this is expected behaviour. Are you sure you're using the latest version? Please could you post the error with full stack trace as there's a multitude of reasons a NullReferenceException could happen.
All the best,
Joel
I don't appear to be getting a null reference exception from ES3.GetKeys on a file with no keys. I've tested this with the following code in the latest version:
Code: Select all
using UnityEngine;
public class GetKeysTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
ES3.DeleteFile();
ES3.Save("key1", 123);
ES3.Save("key2", 123);
ES3.DeleteKey("key1");
ES3.DeleteKey("key2");
// File will now be "{ }"
var keys = ES3.GetKeys(); // Returns an empty array without error.
}
}
All the best,
Joel