发送带有参数的解析云代码时出现 IllegalArgumentException
IllegalArgumentException when sending Parse Cloud Code with Arguments
我在发送带有 HashMap 参数的云代码请求时遇到问题。有趣的是,如果我发送一个带有空参数的请求,它工作得很好。
这是我的请求代码(更新了 ishmaelMakitla 的回答):
Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", new String[]{"hey"});
ParseCloud.callFunctionInBackground("", par, new FunctionCallback() {
@Override
public void done(Object o, Throwable throwable) {
Log.v("28", "" + o);
Log.v("27", "" + throwable.getMessage());
for (Object obj : (ArrayList)o) {
Log.v("29",""+((ParseObject) obj).get("title"));
}
}
@Override
public void done(Object object, ParseException e) {
Log.v("26", "" + object);
if (e != null) {
Log.v("27", "" + e);
}
for (Object obj : (ArrayList)object) {
Log.v("25",""+((ParseObject) obj).get("title"));
}
}
});
还有我的云代码方法:
Parse.Cloud.define ('getFoo', function (req, res) {
var arrayIngredients = [];
arrayIngredients = req.params.ingredients;
var recepyQuery = new Parse.Query("Foos");
recepyQuery.find( {
success: function(result) {
res.success(result);
},
error: function() {
res.error("Nothing here");
}
});
});
此代码完美运行,但如果我取消注释 par.put(...) 部分,则会出现此错误:
com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
这是我的错误堆栈:
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.parse.ParseTaskUtils.run(ParseTaskUtils.java:114)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Looper.loop(Looper.java:146)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5653)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at dalvik.system.NativeStart.main(Native Method)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: Caused by: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseEncoder.encode(ParseEncoder.java:136)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseEncoder.encode(ParseEncoder.java:97)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCommand.<init>(ParseRESTCommand.java:138)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCloudCommand.<init>(ParseRESTCloudCommand.java:22)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCloudCommand.callFunctionCommand(ParseRESTCloudCommand.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloudCodeController.callFunctionInBackground(ParseCloudCodeController.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.then(ParseCloud.java:64)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.then(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:726)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.then(Task.java:818)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.then(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:690)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:796)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:830)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:99)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.starter.MainActivity.onCreate(MainActivity.java:62)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.Activity.performCreate(Activity.java:5541)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.access0(ActivityThread.java:172)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: ... 7 more
这是我的错误还是 Parse 有问题?
我正在使用 Parse Server 和 Parse 的 Android SDK 1.13.0
不要在值中传递 String[]
,只需传递一个 String
,为此您应该更改您的请求代码,如下所示 -
Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", "someIngredientValue"});
ParseCloud.callFunctionInBackground("getFoo", par, new FunctionCallback() {
@Override
public void done(Object o, Throwable throwable) {
Log.v("28", "" + o);
Log.v("27", "" + throwable.getMessage());
for (Object obj : (ArrayList)o) {
Log.v("29",""+((ParseObject) obj).get("title"));
}
}
//the rest of your code ...
在接收端,你然后说 request.params.ingredients
- 这应该给你 'someIngredientValue'。
希望对您有所帮助。
我在发送带有 HashMap 参数的云代码请求时遇到问题。有趣的是,如果我发送一个带有空参数的请求,它工作得很好。 这是我的请求代码(更新了 ishmaelMakitla 的回答):
Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", new String[]{"hey"});
ParseCloud.callFunctionInBackground("", par, new FunctionCallback() {
@Override
public void done(Object o, Throwable throwable) {
Log.v("28", "" + o);
Log.v("27", "" + throwable.getMessage());
for (Object obj : (ArrayList)o) {
Log.v("29",""+((ParseObject) obj).get("title"));
}
}
@Override
public void done(Object object, ParseException e) {
Log.v("26", "" + object);
if (e != null) {
Log.v("27", "" + e);
}
for (Object obj : (ArrayList)object) {
Log.v("25",""+((ParseObject) obj).get("title"));
}
}
});
还有我的云代码方法:
Parse.Cloud.define ('getFoo', function (req, res) {
var arrayIngredients = [];
arrayIngredients = req.params.ingredients;
var recepyQuery = new Parse.Query("Foos");
recepyQuery.find( {
success: function(result) {
res.success(result);
},
error: function() {
res.error("Nothing here");
}
});
});
此代码完美运行,但如果我取消注释 par.put(...) 部分,则会出现此错误:
com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
这是我的错误堆栈:
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: com.parse.ParseException: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.parse.ParseTaskUtils.run(ParseTaskUtils.java:114)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.os.Looper.loop(Looper.java:146)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5653)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
05-30 11:31:26.265 12612-12612/com.parse.starter W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at dalvik.system.NativeStart.main(Native Method)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: Caused by: java.lang.IllegalArgumentException: invalid type for ParseObject: class [Ljava.lang.String;
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseEncoder.encode(ParseEncoder.java:136)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseEncoder.encode(ParseEncoder.java:97)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCommand.<init>(ParseRESTCommand.java:138)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCloudCommand.<init>(ParseRESTCloudCommand.java:22)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseRESTCloudCommand.callFunctionCommand(ParseRESTCloudCommand.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloudCodeController.callFunctionInBackground(ParseCloudCodeController.java:28)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.then(ParseCloud.java:64)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.then(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:726)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.then(Task.java:818)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.then(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.run(Task.java:917)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.completeAfterTask(Task.java:908)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:715)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.continueWithTask(Task.java:690)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:806)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:796)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at bolts.Task.onSuccessTask(Task.java:830)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:60)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.ParseCloud.callFunctionInBackground(ParseCloud.java:99)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at com.parse.starter.MainActivity.onCreate(MainActivity.java:62)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.Activity.performCreate(Activity.java:5541)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2368)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2464)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread.access0(ActivityThread.java:172)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
05-30 11:31:26.275 12612-12612/com.parse.starter W/System.err: ... 7 more
这是我的错误还是 Parse 有问题? 我正在使用 Parse Server 和 Parse 的 Android SDK 1.13.0
不要在值中传递 String[]
,只需传递一个 String
,为此您应该更改您的请求代码,如下所示 -
Map<String, Object> par = new HashMap<String, Object>();
par.put("ingredients", "someIngredientValue"});
ParseCloud.callFunctionInBackground("getFoo", par, new FunctionCallback() {
@Override
public void done(Object o, Throwable throwable) {
Log.v("28", "" + o);
Log.v("27", "" + throwable.getMessage());
for (Object obj : (ArrayList)o) {
Log.v("29",""+((ParseObject) obj).get("title"));
}
}
//the rest of your code ...
在接收端,你然后说 request.params.ingredients
- 这应该给你 'someIngredientValue'。
希望对您有所帮助。