我试图调用我使用Android NDK从C编写的一些Java代码.该应用程序是NativeActivity应用程序.我必须访问一些仅在Java中可用的功能,并且该功能要求您子类化另一个类,所以我不能直接从C执行调用.因此,我有这样的Java代码:
// src/com/example/my/package/SubClass.java
package com.example.my.package;
import android.foo.TheSuperClass;
public class SubClass extends TheSuperClass {
public SubClass() {
setImportantProperty(true);
}
}
Run Code Online (Sandbox Code Playgroud)
我也有这样的C代码:
// Some file.c
void setThatImportantJavaProperty() {
JavaVM *vm = AndroidGetJavaVM(); // This returns a valid JavaVM object
JNIEnv* env;
(*vm)->AttachCurrentThread(vm, &env, 0);
jclass theSubClass = (*env)->FindClass(env, "com/example/my/package/SubClass");
jthrowable exception = (*env)->ExceptionOccurred(env);
if (exception) {
(*env)->ExceptionDescribe(env);
// This gives me: "java.lang.NoClassDefFoundError: [generic]".
// Also, theSubClass is null, so the next line causes a segfault.
}
jmethodID theSubClassConstructor = (*env)->GetMethodID(env, theSubClass, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个非常简单的字典,将字符串映射到Swift中的字符串数组.代码如下所示:
class FirstViewController: UIViewController {
var characters:[String] = []
var adjacency = [String : [String]?]()
override func viewDidLoad() {
super.viewDidLoad()
characters = loadCharacters()
adjacency = loadAdjacency()
var character:String = characters[0]
var adj:[String] = adjacency[character] // This line gives the first compiler error
adj = adjacency["a"] // This line gives the second compiler error
println(adj)
}
func loadCharacters() -> [String] {
return ["a", "b", "c"]
}
func loadAdjacency() -> [String : [String]?] {
return ["a": ["a", "b", "c"], "b": ["b", "c", …Run Code Online (Sandbox Code Playgroud)