2012-11-25 35 views
10
  • sử dụng PhoenGap 2.2.0
  • đã thi \ bin \ tạo C: \ Temp \ Test com Kiểm tra .test
  • Đã sau đầu ra

Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.lỗi chưa gặp: Object # <Object> không có phương pháp 'exec' tại file: ///android_asset/www/index.html

Creating new android project... 
Building jar and js files... 
Copying template files... 
Copying js, jar & config.xml files... 
Copying cordova command tools... 
Updating AndroidManifest.xml and Main Activity... 
  • nhập khẩu dự án
  • 012.351.
    • trên Eclipse (4.2.0) đã
    • File> New> Project> Android> Dự án Android từ hiện tại Mã
    • chọn thư mục C: \ Temp \ Test
    • Checked "Dự án Sao chép vào không gian làm việc"
  • Làm thay đổi
    • Checked res \ xml \ config.xml và dòng <plugin name="Notification" value="org.apache.cordova.Notification"/> hiện diện
    • Kiểm tra chỉ số. html có cordova-2.2.0.js bao gồm
    • Case # 1 Khai trương index.html và sửa đổi từ

<script type="text/javascript"> app.initialize(); </script>

để

<script type="text/javascript"> 
function showAlert(msg){ 
navigator.notification.alert(msg); 
} 
document.addEventListener("deviceready", showAlert('You are the winner!'), false); 
app.initialize(); 
</script> 

tôi nhận được lỗi sau 11-25 10:29:58.399: E/Web Console(14604): Uncaught TypeError: Cannot call method 'alert' of undefined at file:///android_asset/www/index.html:40

    • Trường hợp # 2 Chỉ mục đã mở.html và sửa đổi từ

<script type="text/javascript"> app.initialize(); </script>

để

<script type="text/javascript"> 
function successAlert(){} 
function errorAlert(){} 
function showAlert(msg){ 
cordova.exec(successAlert, errorAlert, "Notification","alert", [msg]); 
} 
document.addEventListener("deviceready", showAlert('You are the winner!'), false); 
app.initialize(); 
</script> 

tôi nhận được lỗi sau 11-25 10:25:06.575: E/Web Console(14149): Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/index.html:42 }

Tôi chắc chắn rằng tôi đã bỏ lỡ một cái gì đó ... chỉ tôi không thể kết luận nó là gì. Hãy giúp tôi ra.

+0

Chỉ cần một FYI: Tôi đang phải đối mặt với những vấn đề này trên thiết bị trực tiếp khi triển khai sử dụng USB. Tôi đã không thử bất cứ điều gì khác. Hệ điều hành Android: 4.2 – javadevg

+0

Tôi gặp lỗi --Không kích hoạt Loại lỗi: Đối tượng # không có phương thức 'exec' - cũng như và không thể tìm thấy giải pháp nào. Tôi đã bao gồm "cordova-2.2.0.js" vào "index.html" của tôi và gọi "nfc.addNdefListener (gọi lại, [thành công], [lỗi]);" được triển khai trong "phonegap-nfc.js". Trong đó có "cordova.exec();" phương pháp được gọi. Tôi đang sử dụng cordova 2.2.0 và plugin phonegap-nfc https://github.com/chariotsolutions/phonegap-nfc. Nhưng nó không hoạt động ngay cả khi tôi gọi phương thức exec trực tiếp trong index.html. – Yves

Trả lời

11

này sẽ gọi showAlert ngay lập tức, thay vì trì hoãn đến khi sự kiện cháy:

document.addEventListener("deviceready", showAlert('You are the winner!'), false) 

Thay vì làm điều này

document.addEventListener("deviceready", function() { 
    showAlert('You are the winner!') 
}, false) 
+0

Cảm ơn giải pháp. – javadevg

+0

Cảm ơn bạn! Nó hoạt động tốt. – Hogun

Các vấn đề liên quan