문제

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()

도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top