我正在尝试按照phonegap示例文件编写代码并运行 的问题。
我已经尝试在2.2模拟器实例上运行它 电话:
这是我的代码,它基本上是写入的近似逐字粘贴 来自API docs + jsconsole和控制台消息的文件代码:
<script type="text/javascript" src="http://jsconsole.com/remote.js?
[key_ommited]"></script>
<script> console.log('in between loads.'); </script>
<script type="text/javascript" src="phonegap-1.0.0.js"></script>
<script> console.log('after-phonegap.'); </script>
<script type="text/javascript">
console.log('test to see if this fires within new script tag');
//
// // Wait for PhoneGap to load
// //
// console.log('before add event listener!!');
//
document.addEventListener("deviceready", onDeviceReady,
false);
console.log('after event listener declaration');
function onDeviceReady() {
console.log('in onDeviceReady');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS,
fail);function fail);(args) {
}
var test_file_full_path = 'mnt/sdcard/test_file2.txt'
function gotFS(fileSystem) {
fileSystem.root.getFile(test_file_full_path, { create:
true }, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.onwrite = function(evt) {
console.log("write success");
};
writer.write("some sample text");
// contents of file now 'some sample text'
writer.truncate(11);
// contents of file now 'some sample'
writer.seek(4);
// contents of file still 'some sample' but file pointer
is after the 'e' in 'some'
writer.write("different text");
// contents of file now 'some different text'
}
function fail(error) {
console.log('in failure: ');
console.log(error.code);
}
第一次运行代码时,我从jsconsole获得了什么 输出(底部最旧的消息)是:
"write success"
"Error in success callback: File4 = 7"
"This is a file"
"in onDeviceReady"
"test to see if this fires within new script tag"
"after-phonegap."
"after event listener declaration"
"in between loads."
随后我运行相同的代码时,我得到:
"9"
"in failure: "
"in onDeviceReady"
[rest of messages are the same]
如果我进入DDMS视角,我看到生成的'test_file2' 文件在目录中,但如果我尝试拉动生成的'test_file2' 文件,它不会让我把它从模拟器上拉出来并说:
[2011-09-30 14:47:32] Failed to pull selection
[2011-09-30 14:47:32] (null)
我也无法删除此文件。
在之前的尝试中,我能够拉出文件,看到了 写代码的第一行'一些示例文本'已经写好了,但是 大概它已经停止了其他写行。
任何人都知道我做错了什么/有什么建议吗?写这篇文件困扰着我,我遇到了多少麻烦。