[solved] file.externalDataDirectory is sometimes null but sometimes not


I have this code:

constructor(private file: File) {}


    var filesDirectory = this.file.externalDataDirectory;
    this.file.readAsText(filesDirectory, 'songs.json')
        .then((text) => {
          let jsonObj: any = JSON.parse(text);
        .catch(error => {

in like 50% of the times I run the app, the console log for file.externalDataDirectory gives me “null”, and the other 50% it gives the right path. why is that happening?
the times it is “null” the rest of the function doesn’t not work saying “Expected String, but got Null.”

I’m running it on an android device

oops. sorry guys, I forgot to perform the platform.ready() check, that was the problem. the case is solved. my bad.