phonegap Class not found at file:///android_asset/www/cordova-2.0.0.js:938

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

i try to use this plugin and followed the instruction given in the readme.md file.

1)here's my html file

<!DOCTYPE HTML> <html> <head>     <title>TryMakan Video</title>     <link rel="stylesheet" href="style.css" /> <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>     <script type="text/javascript" charset="utf-8" src="video.js"></script>     <script type="text/javascript"> function playVideo(){             window.plugins.videoPlayer.play("http://www.trymakan.my/wp-content/uploads/2011/09/NASI-AYAM-BEREMPAH-KAJANG.mp4");         }  </script> </head> <body> <a href="#" onClick="playVideo();">play</a> </body></html> 

2) here's my plugins.xml which is located in xml folder

<?xml version="1.0" encoding="utf-8"?> <plugins>     <plugin name="VideoPlayer" value="com.phonegap.plugins.video.VideoPlayer"/> </plugins> 

3) i've also copied the VideoPlayer.java into this folder src\com\phonegap\plugins\video

4) additionally, some said I also need to add the plugin into AndroidManifest.xml file, so this is a snippet of it

<application         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/AppTheme" >         <activity             android:name=".MainActivity"             android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"             android:label="@string/title_activity_main" >             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <action android:name="com.phonegap.plugins.video.VideoPlayer"/>                 <category android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity>     </application> 

but still, when I click on 'play', log cat will return this error

08-08 04:54:15.823: I/Web Console(309): Error: Status=2 Message=Class not found at file:///android_asset/www/cordova-2.0.0.js:938 

update1: here's where the VideoPlayer.java is located

here

I don't see the VideoPlayer.java under Gen folder, does that means it's not compiled? Could this be the problem? If yes, how to solve it?

update2: I checked bin folder, and there VideoPlayer.class under bin\classes\com\phonegap\plugins\video so the VideoPlayer.java is actually compiled

回答1:

the problem is your plugins.xml.

it appears in one of the recent PhoneGap release, the plugins.xml has been removed and you have to add the line in res/xml/config.xml instead.

so try adding the tag <plugin name="VideoPlayer" value="com.phonegap.plugins.video.VideoPlayer"/>

to res/xml/config.xml not to plugins.xml



回答2:

If the error shown in the log is

Class not found at file:///android_asset/www/cordova-2.0.0.js:938

The best way is to check which class is causing the error. For those who still get this error message, try the following trick.

  1. Open cordova-2.0.0.js in an editor.
  2. Replace code on Line 938 i.e.

    console.log("Error: Status="+v.status+" Message="+v.message);

    with

    console.log("Error: Status="+v.status+" Message="+v.message+" service="+service+" action="+action);

  3. Run the app again and check the console for the above error. You can see the plugin which causes the error in service=XYZ where XYZ is the plugin name.

  4. Check if the section in your config.xml file has any entry for the XYZ plugin.
  5. Add the XYZ plugin if not found.


回答3:

I have had this error because of a missing plugin. I Added

<plugin name="Device" value="org.apache.cordova.Device"/> 

to the config.xml file and it fixed it.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!