Question

I made a simple beanshell ide in android using an edittext and a button. When the button is clicked, Interpreter.eval() is called and edittext.getText().toString() is passed in as the parameter. I want to know: how can I make a method in beanshell and run it?

This is the code i m trying to execute in my beanshell ide:

import android.widget.Toast

int i=add(1, 5);
Toast.makeText(context, ""+i, 5000).show();

int add(int i, int j){
    return i+j;
}

But i get the following error:

Command not found: add()

Was it helpful?

Solution

Have you tried moving your function definition above its usage, like so;

import android.widget.Toast

int add(int i, int j){
    return i+j;
}

int i=add(1, 5);
Toast.makeText(context, ""+i, 5000).show();

Does that make any difference?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top