Skip to content

com.hippo.quickjs.android.JSEvaluationException: null at fib.js:1 #12

Description

@bjhexn
QuickJS quickJS = new QuickJS.Builder().build();
JSRuntime runtime;
JSContext jsContext;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quick_jsactivity);

    initJSContent();
    demo();
}

private void initJSContent() {
    runtime = quickJS.createJSRuntime();
    jsContext = runtime.createJSContext();
}

private void demo() {
    String script1 = "" +
            "function fib(n) {" +
            "  return n;" +
            "}";
    jsContext.evaluate(script1, "fib.js");
    int result = jsContext.evaluate("fib(6)", "fib.js", int.class);
    LogUtils.log("demo result = " + result );
}

@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.btn_quick_js) {
        //initJSContent();
        demo();
    } else if (id == R.id.btn_quick_js2) {
        demo();
    }
}

"demo()" execute in onCreate() is 0K , but tap button execute "demo" happened crash. If initialize " initJSContent();" in onClick, no crash。 “JSContent” may be reused ?

是否有遇到同样的问题? jscontent 是否可以复用?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions