无法转换' const bool'到了工作

时间:2015-05-21 08:11:09

标签: c++ hashmap java-native-interface

我需要向object map添加bool,我的 CGSize size = CGSizeZero; if ([label.text respondsToSelector: @selector(boundingRectWithSize:options:attributes:context:)] == YES) { size = [label.text boundingRectWithSize: constrainedSize options: NSStringDrawingUsesLineFragmentOrigin attributes: @{ NSFontAttributeName: label.font } context: nil].size; } else { size = [label.text sizeWithFont: label.font constrainedToSize: constrainedSize lineBreakMode: UILineBreakModeWordWrap]; } 被定义为基元,我需要将其转换为对象。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以将bool转换为jboolean,然后将jboolean列入带有JNI调用的布尔作业,如下所示:

jboolean value = true;

jclass booleanClass = env->FindClass("java/lang/Boolean");
jmethodID methodID = env->GetMethodID(booleanClass, "<init>", "(Z)V", false);
jobject booleanObject = env->NewObject(booleanClass, methodID, value);