2017-06-26 45 views
1

的特性「filesystemName」我有在下面的邏輯沒有忘記第二時間我上運行的Android應用程序的應用程序:科爾多瓦錯誤:無法讀取空

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
        function(fs) { 
         console.log('Success!', fs); 
        }, 
        function(e) { 
         console.error('Fail!', e); 
        } 
       ); 

錯誤我得到的是:

cordova.js:312 Error in Success callbackId: File1306990920 : TypeError: Cannot read property 'filesystemName' of null

Cordova.js線312是在callbackFromNative功能的通用陷阱。

有沒有人遇到過這個?

補救措施是什麼?

回答

0

UPDATE

單從config.xml中刪除<preference name="AndroidPersistentFileLocation" value="Compatibility" />,或更改"Compatibility""Internal",似乎是負責添加的空值的陣列響應,提及以下


我使用帶有Ionic2的cordova文件插件,如果不是你的情況,也許這可以給你一些亮點。

我的這個錯誤的跟蹤帶我到.../plugins/cordova-plugin-file/www/fileSystems-roots.js,即fsName的地圖 - > FileSystem。

這使我認爲這是一個錯誤,但我不確定如何報告它。

不管怎麼說,問題是到地圖響應包含一個空的對象,因爲你可以在下面的響應的抄見:

[ 
    null 
    , {"fullPath":"/","filesystemName":"persistent","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""} 
    , {"fullPath":"/","filesystemName":"content","isDirectory":true,"nativeURL":"content:...","filesystem":1,"isFile":false,"name":""} 
    , {"fullPath":"/","filesystemName":"assets","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""} 
    , {"fullPath":"/","filesystemName":"cache","isDirectory":true,"nativeURL":"file:...","filesystem":1,"isFile":false,"name":""} 
] 

同樣,我使用ionic2,如果是你的情況同樣,你可以使用文件直接插件,之後的下一個步驟:

0-安裝插件(如果您收到此錯誤,我想你已經做了這一步)

1導入插件作爲提供者在你模塊中,就像

import { File } from '@ionic-native/file'; 

@NgModule({ 
    ... 
    , providers: [ 
     ... 
     , File 
     ... 
    ] 
    ... 
}) 

2-添加插件作爲供應商在你的組件

import { File } from '@ionic-native/file'; 

export class FileCreatorComponent { 
    constructor(..., private file: File, ...) { } 

3-根據Ionic2 Native file plugin此頁面使用它,例如創建(並覆蓋是否存在),你可以這樣做:

createFile() { 
    var filePath= this.file.externalRootDirectory + 'Download/'; 
    //var filePath= 'file:///storage/emulated/0/Download/'; If the first doesn't work you can put this path, NOT RECOMMENDED, because the first should work 
    var fileName= 'newOne.txt'; 

    this.file.writeFile(filePath, fileName, 'Lorem ipsum', { replace: true }) 
       .then(() => { 
        console.log('File created'); 
       }); 
}