【问题标题】:Error running phonegap camera sample运行 phonegap 相机示例时出错
【发布时间】:2013-09-29 23:45:45
【问题描述】:

您好,我尝试在我的 Sony Xperia E 设备上运行 phonegap camera sample。该应用程序在设备中正确启动,但是当我点击“捕获照片”按钮时,我得到了警告框,显示“失败,因为:找不到类”。在 Eclipse 的 LogCat 视图中,我发现了这些错误日志:

W/System.err: java.lang.ClassNotFoundException: org.apache.cordova.CameraLauncher
W/System.err:   at java.lang.Class.classForName(Native Method)
W/System.err:   at java.lang.Class.forName(Class.java:217)
W/System.err:   at java.lang.Class.forName(Class.java:172)
W/System.err:   at org.apache.cordova.PluginEntry.getClassByName(PluginEntry.java:117)
W/System.err:   at org.apache.cordova.PluginEntry.createPlugin(PluginEntry.java:93)
W/System.err:   at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:264)
W/System.err:   at org.apache.cordova.PluginManager.execHelper(PluginManager.java:219)
W/System.err:   at org.apache.cordova.PluginManager.exec(PluginManager.java:214)
W/System.err:   at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
W/System.err:   at android.webkit.WebViewCore.nativeMouseClick(Native Method)
W/System.err:   at android.webkit.WebViewCore.nativeMouseClick(Native Method)
W/System.err:   at android.webkit.WebViewCore.access$6700(WebViewCore.java:57)
W/System.err:   at android.webkit.WebViewCore$EventHub.dispatchWebKitEvent(WebViewCore.java:1856)
W/System.err:   at android.webkit.WebViewInputDispatcher.dispatchWebKitEvent(WebViewInputDispatcher.java:689)
W/System.err:   at android.webkit.WebViewInputDispatcher.dispatchWebKitEvents(WebViewInputDispatcher.java:639)
W/System.err:   at android.webkit.WebViewInputDispatcher.access$800(WebViewInputDispatcher.java:78)
W/System.err:   at android.webkit.WebViewInputDispatcher$WebKitHandler.handleMessage(WebViewInputDispatcher.java:1153)
W/System.err:   at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err:   at android.os.Looper.loop(Looper.java:137)
W/System.err:   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:827)
W/System.err:   at java.lang.Thread.run(Thread.java:856)
W/System.err: Caused by: java.lang.NoClassDefFoundError: org/apache/cordova/CameraLauncher
W/System.err:   ... 21 more
W/System.err: Caused by: java.lang.ClassNotFoundException: org.apache.cordova.CameraLauncher
W/System.err:   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
W/System.err:   at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
W/System.err:   at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
W/System.err:   ... 21 more
I/System.out: Error adding plugin org.apache.cordova.CameraLauncher.
D/PluginManager: exec() call to unknown plugin: Camera

我严格按照文档进行,已经在config.xml中添加了以下项目:

<feature name="Camera">
    <param name="android-package" value="org.apache.cordova.CameraLauncher" />
</feature>

我也成功地从我的 android-sdk 文件夹中运行了这一行:

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git

我已经在 Eclipse 中清理了几次项目并运行了几次,都导致相同的结果。有人知道我哪里错了吗?

谢谢...

PS

  • phonegap 版本:3.0.0-0.14.4
  • cordova 版本:3.0.9

index.html:

<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

var pictureSource;   // picture source
var destinationType; // sets the format of returned value 

// Wait for Cordova to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);

// Cordova is ready to be used!
//
function onDeviceReady() {
    pictureSource=navigator.camera.PictureSourceType;
    destinationType=navigator.camera.DestinationType;
}

// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
    // Uncomment to view the base64 encoded image data
    //alert(imageData);  

    // Get image handle
    //
    var smallImage = document.getElementById('smallImage');
    // Unhide image elements
    //
    smallImage.style.display = 'block';

    // Show the captured photo
    // The inline CSS rules are used to resize the image
    //
    smallImage.src = "data:image/jpeg;base64," + imageData;
}

// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
    alert("inside large image")
    // Uncomment to view the image file URI 
    // console.log(imageURI);

   // Get image handle
   //
    var largeImage = document.getElementById('largeImage');

  // Unhide image elements
  //
    largeImage.style.display = 'block';

  // Show the captured photo
  // The inline CSS rules are used to resize the image
  //
    largeImage.src = imageURI;
}

// A button will call this function
//
function capturePhoto() {
  // Take picture using device camera and retrieve image as base64-encoded string
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
    destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function capturePhotoEdit() {
  // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
    navigator.camera.getPicture(onPhotoDataSuccess, onFail,
    { quality: 20, allowEdit: true,
    destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function getPhoto(source) {
  // Retrieve image file location from specified source
    navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
    destinationType: destinationType.FILE_URI,
    sourceType: source });
}


// Called if something bad happens.
// 
function onFail(message) {
    alert('Failed because: ' + message);
}

</script>
</head>
<body>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
</body>
</html>

【问题讨论】:

    标签: android plugins cordova camera


    【解决方案1】:

    我刚刚从 Camera API 文档中检查了这个 git(git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git),它的 src/android/CameraLauncher.java 文件的包名是 com.apache.cordova.camera 如果你的源代码也使用这个包名,那么你的配置文件值应该更改为org.apache.cordova.camera.CameraLauncher

    【讨论】:

    • 我的phonegap版本是3.0.0-0.14.4,cordova版本是3.0.9。我认为他们不再使用plugins.xml。在docs.phonegap.com/en/3.0.0/cordova_camera_camera.md.html#Camera之后,我将相机插件添加到config.xml
    • 当你输入“phonegap 本地插件列表”时,你的插件是否出现在列表中?
    • 显示 T:\tmp\phonegapapp>phonegap 本地插件列表 [phonegap] org.apache.cordova.camera [phonegap] org.apache.cordova.device [phonegap] org.apache.cordova。媒体捕获
    • hmm,,,奇怪的是日志消息说你的相机插件是未知的。您是否检查过您的服务名称与 JavaScript exec 调用中使用的名称匹配?
    • 我在问题中添加了 index.html 源代码。全部来自phonegap camera api文档
    【解决方案2】:

    config.xml 中将 org.apache.cordova.CameraLauncher 更改为 org.apache.cordova.camera.CameraLauncher

    这对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多