找不到类 在电话间隙安卓中出现异常
Class not found Exception in phonegap android
我正在尝试通过电子邮件和短信在phonegap中发送照片图像,因此编写了充当Java本机代码桥梁的插件。 问题是当我从html单击共享按钮时 弹出"找不到类"警报。 即使插件名称在 config.xml 文件中正确声明, 我收到此错误, 请帮助我..
这是它的java代码。
public class Share extends CordovaPlugin {
private FileOutputStream outStream;
private File file;
Bitmap bm;
public static final String ACTION_POSITION = "ShareImage";
Context context;
public Share(Context context) {
this.context = context;
}
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
throws JSONException {
if (ACTION_POSITION.equals(action)) {
try {
JSONObject arg_object = args.getJSONObject(0);
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setType("image/jpg");
String uri = "@drawable/"+arg_object.getString("image")+".jpg";
int imageResource = context.getResources().getIdentifier(uri, null, context.getPackageName());
bm = BitmapFactory.decodeResource( context.getResources(), imageResource);
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
file = new File(extStorageDirectory+ "/Download/", "imageee.png");
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (FileNotFoundException e) {
System.out.println(" praise god........");
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, arg_object.getString("image"));
this.cordova.getActivity().startActivity(sendIntent);
} catch (Exception e) {
System.err.println("Exception: " + e.getMessage());
callbackContext.error(e.getMessage());
return false;
}
}
return true;
}
}
分享.js插件
var Share = function() {};
Share.prototype.show = function(success, fail, path) {
return cordova.exec( function(args) {
success(args);
}, function(args) {
fail(args);
}, 'Share','', 'ShareImage', [{"image": path}]);
};
if(!window.plugins) {
window.plugins = {};
}
if (!window.plugins.share) {
window.plugins.share = new Share();
}
在配置.xml文件中声明插件
<plugins>
<plugin name="Share" value="com.picsswipe.Share"/>
</plugins>
日志猫
11-11 16:02:04.898: W/System.err(15149): java.lang.InstantiationException: com.picsswipe.Share
11-11 16:02:04.898: W/System.err(15149): at java.lang.Class.newInstanceImpl(Native Method)
11-11 16:02:04.898: W/System.err(15149): at java.lang.Class.newInstance(Class.java:1409)
11-11 16:02:04.898: W/System.err(15149): at org.apache.cordova.api.PluginEntry.createPlugin(PluginEntry.java:80)
11-11 16:02:04.898: W/System.err(15149): at org.apache.cordova.api.PluginManager.getPlugin(PluginManager.java:249)
11-11 16:02:04.898: W/System.err(15149): at org.apache.cordova.api.PluginManager.exec(PluginManager.java:206)
11-11 16:02:04.898: W/System.err(15149): at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:51)
11-11 16:02:04.898: W/System.err(15149): at android.webkit.WebViewCore.nativeHandleTouchEvent(Native Method)
11-11 16:02:04.898: W/System.err(15149): at android.webkit.WebViewCore.nativeHandleTouchEvent(Native Method)
11-11 16:02:04.898: W/System.err(15149): at android.webkit.WebViewCore.access$6200(WebViewCore.java:54)
11-11 16:02:04.898: W/System.err(15149): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1658)
11-11 16:02:04.898: W/System.err(15149): at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 16:02:04.898: W/System.err(15149): at android.os.Looper.loop(Looper.java:130)
11-11 16:02:04.898: W/System.err(15149): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:685)
11-11 16:02:04.898: W/System.err(15149): at java.lang.Thread.run(Thread.java:1019)
11-11 16:02:04.898: I/System.out(15149): Error adding plugin com.picsswipe.Share.
HTML文件的点击功能
instance.addEventHandler(PhotoSwipe.EventTypes.onToolbarTap, function(e){
if (e.toolbarAction === PhotoSwipe.Toolbar.ToolbarAction.none){
share();
}
});
function share() {
window.plugins.share.show({path: "Image"},
function(e) {
alert(e) }, // Success function
function() {
alert("Praise god :( ")
},// Failure function
imagename
);
}
请进行这些更改。在这里我把你所有的js代码
var Share = function() {};
Share.prototype.show = function(success, fail, path) {
return PhoneGap.exec(function(args) {success(args);}, function(args) {fail(args);}, 'Share', 'ShareImage', [{"image": path}]);
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin("share", new Share());
});
instance.addEventHandler(PhotoSwipe.EventTypes.onToolbarTap, function (e) {
if (e.toolbarAction === PhotoSwipe.Toolbar.ToolbarAction.none) {
share();
}
});
function share() {
var imagename = ""; // Please give your image name here or page from share() function
Share.prototype.show({path: "Image"},function (e) {alert(e);},function () {alert("Praise god :( ");},imagename);
}
配置.xml
<feature name="Share">
<param name="android-package" value="$Share.java file package name$"/>
</feature>
例:
<feature name="Share">
<param name="android-package" value="org.apache.cordova.plugin.Share"/>
</feature>
为了获得最佳方法,您可以为所有Phonegap插件创建软件包名称package org.apache.cordova.plugin;
。
我没有检查您的共享.java文件。我已经在这里分享了我的工作短信插件代码
请让我知道您有任何问题。
请删除以下代码
public Share(Context context) {
this.context = context;
}
相关文章:
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 在javaservlet doPost方法中启动线程时,无法返回异常消息
- document.applet.method在Mounatin Lion上抛出safari 6+JDK7异常
- 为什么浏览器没有为语法错误抛出异常
- java,javascript签名的小程序(文件选择,ftp上传)安全性/套接字异常
- node.js和express中的异常处理
- 派生进程的stdout在管道传输时工作异常
- NodeJS和pg promise,捕获PostgreSQL异常
- 当显式定义控制器参数时,默认模型绑定器会发生异常
- 显示引导弹出操作异常的逻辑
- 调用谷歌地图路线服务时未捕获的异常
- web配置http到https重定向异常
- 转换异常时间&Datestring到JavaScript日期
- 为什么在python中使用异常比javascript更容易接受
- PHP REST服务抛出异常——希望避免控制台错误
- JS异常:animate不是一个函数
- 在蓝鸟中处理异常
- Meteor:异步函数回调异常:onAfterAction
- 在js中捕获自定义异常
- 找不到类 在电话间隙安卓中出现异常