I am creating a simple plug-in to generate Fibonacci series. In my java code I h

I am creating a simple plug-in to generate Fibonacci series. In my java code I have used ArrayList<Integer> a = new ArrayList<Integer>() to store all the numbers in an Array. At the end of the code, I return the ArrayList object i.e return a. But when I call my function in Expression Rule after exporting the plugin to the plugin folder, the function doesn't seem to exist. Is this because I am returning an Array of values? What should I do to generate an array of values?

I had made another simple plug-in to fetch the factorial of a number. This worked successfully.

OriginalPostID-223874

OriginalPostID-223874

  Discussion posts and replies are publicly visible

Parents
  • my function appear in the expression rule. My java code for fibonacci series plugin is:

    import java.util.ArrayList;

    import org.apache.log4j.Logger;

    import com.appiancorp.services.ServiceContext;
    import com.appiancorp.suiteapi.expression.annotations.Function;
    import com.appiancorp.suiteapi.expression.annotations.Parameter;
    import com.appiancorp.suiteapi.type.AppianType;


    @MathfunctionCategory
    public class fibonacci {

              private static final Logger LOG = Logger.getLogger(fibonacci.class);

              @SuppressWarnings("deprecation")
              @Function(returnType=AppianType.ARRAY)
              public Integer[] fibonacci(ServiceContext sc, @Parameter(type=AppianType.INTEGER) int fibo) {
                        ArrayList<Integer> a = new ArrayList<Integer>();
                        int a0=0, a1=1;
                        a.add(a0);
                        a.add(a1);
                        int a2=0;
                        for(int i=2;i<fibo;i++)
                        {
                                  a2=a0+a1;
                                  a.add(a2);
                                  a0=a1;
                                  a1=a2;
                        }
                        
                        return (Integer[]) a.toArray();
              }

    }

    I get the error:

    Expression evaluation error : Unresolved compilation problem: Type mismatch: cannot convert from Object[] to Integer[]
  • 0
    Certified Senior Developer
    in reply to zianf

    hi @zianf can you please learn me how to create plugin s in java code

Reply Children