Javascript 无法读取属性';铬';未定义的

Javascript 无法读取属性';铬';未定义的,javascript,google-chrome-app,html5-filesystem,Javascript,Google Chrome App,Html5 Filesystem,是什么导致了它以及如何避免它?我无法捕捉到异常情况。 第一次取消chooseEntry时createWriter有时会抛出异常,我可以捕捉到以下异常: Error in response to fileSystem.chooseEntry: TypeError: Cannot call method 'createWriter' of undefined 然后,当我再次尝试调用ChooseSentry时,会引发此异常: try{ chrome.fileSystem.chooseEntr

是什么导致了它以及如何避免它?我无法捕捉到异常情况。
第一次取消chooseEntry时createWriter有时会抛出异常,我可以捕捉到以下异常:

Error in response to fileSystem.chooseEntry: TypeError: Cannot call method 'createWriter' of undefined
然后,当我再次尝试调用ChooseSentry时,会引发此异常:

try{
    chrome.fileSystem.chooseEntry({ type:'saveFile',suggestedName:$("#mydiv").text()+".jpg",accepts:[{ extensions:['jpg'] }] },function(fileEntry){
        try{
            fileEntry.createWriter(function(writer) {
                writer.onerror = errorHandler;
                writer.onwriteend = function(e) { console.log('write complete'); };
                writer.write(data); //data is a blob
            });
        }catch(err){ console.log("error",err.message); }
    });
}catch(err){ console.log("error",err.message); }

> Error in response to fileSystem.chooseEntry: TypeError: Cannot read property 'chrome' of undefined

要避免第一个异常,请检查fileEntry中是否存在未定义项

       try{
          if(fileEntry) { 
              fileEntry.createWriter(function(writer) {
                writer.onerror = errorHandler;
                writer.onwriteend = function(e) { console.log('write complete'); };
                writer.write(data); //data is a blob
             });
           }
        }catch(err){ console.log("error",err.message); }

检查回调函数中的
fileEntry
参数,当您取消它时,它可能为null。我认为这可以解决这两个错误。非常感谢,我会继续查的。