Custom extension error

Hello people
I m trying to make a function which will take 5 integers, do something with them and then return a list of the result 5 integers.
something like that:


The code I used is this…

public class Extensionic extends AndroidNonvisibleComponent implements Component {
@SimpleFunction(description = “create points”)
public static ArrayList WeirdFunction(int a, int b, int c, int d, int e) {
ArrayList points = new ArrayList();
// do something with the numbers here and come up with 5 other integers h, i, j, k, l
points.add(h);
points.add(i);
points.add(j);
points.add(k);
points.add(l);
return points;
}
}

and it gives me this error:
[javac] An annotation processor threw an uncaught exception.
[javac] Consult the following stack trace for details.
[javac] java.lang.IllegalArgumentException: Cannot convert Java type ‘java.util.ArrayList<java.lang.Integer>’ to Yail type

The declarations should be ok because when i comment out this function and i use a function like:
@SimpleFunction(description = “Simple addition of 5 numbers”)
public int Addition(int a, int b, int c, int d, int e) {
return a + b + c + d + e;
}

it works fine

Any ideas ?

thanks
Niko

Hi!

You can’t set method’s return type to ArrayList, you must return YailList which is a list object used in App Inventor if you want to return a list.

Because ArrayLists can contain every type of value, but YailList is only an array which contains String values.

Convert your ArrayList to YailList by given ways in the docs.

http://3nportal.com/AIBridge/API/com/google/appinventor/components/runtime/util/YailList.html

Convert all items in the ArrayList to String and add this line to the end of the method.

return YailList.makeList(points);
1 Like

Hello @yusufcihan and forgive my ignorance since i dont have a prior experience in java.

You mean the result list will contain strings instead of integers ?

Yeah, don’t worry about using it in App Inventor, they will be behaved as integers in App Inventor, so you will able to use Math blocks with result.

So “100” as String and 100 as Integer is same to the App Inventor.

ok,
so if i dont become very pushy, what else should i change in order to make it work ?

public class Extensionic extends AndroidNonvisibleComponent implements Component {
@SimpleFunction(description = “create points”)
public static ArrayList WeirdFunction(int a, int b, int c, int d, int e) {
   ArrayList points = new ArrayList();
   // do something with the numbers here and come up with 5 other integers h, i, j, k, l
   points.add(h);
   points.add(i);
   points.add(j);
   points.add(k);
   points.add(l);
   return YailList.makeList(points);
   }
}

I dont think that by just adding “return YailList.makeList(points);” i will make it work.

Add .toString() to the letters and try building your extension.

points.add(h.toString());
   points.add(i.toString());
   points.add(j.toString());
   points.add(k.toString());
   points.add(l.toString());

I found this thread here…:


it says:

Creating a YailList
This code demonstrates how you can return a list which is compatible with all the functions in the list category from the App Inventor website.

import com.google.appinventor.components.runtime.util.YailList;
import java.util.ArrayList;
import java.util.List;
...
List listItems = new ArrayList();
listItems.add(data);
return YailList.makeList(listItems);

so i should make it something

public class Extensionic extends AndroidNonvisibleComponent implements Component {
@SimpleFunction(description = “create points”)
public static ArrayList WeirdFunction(int a, int b, int c, int d, int e) {
   List points = new ArrayList();
   // do something with the numbers here and come up with 5 other integers h, i, j, k, l
   points.add(h);
   points.add(i);
   points.add(j);
   points.add(k);
   points.add(l);
   return YailList.makeList(points);
   }
}

or not ?

Actually there are different ways to do it. This is how progamming languages works :slightly_smiling_face:. You can convert List, ArrayList and Object[] to the YailList. YailList supports converting from these types.

Try building your extension with current changes and see what will happen

you re right
i m not new in programming but i m new in Java + Kodular
I didnt plan to make an extension at all
But the app went too far and i thought about making a couple of extensions to get rid of a lot of blocks

I understand you, but there are a lot of extensions are built already, so before creating a new one you should maybe look at the current extensions to find something useful for you.

Taifun has a large collection of extensions for App Inventor in all time. I recommend you to look at the collection :grin:

http://puravidaapps.com/extensions.php

If you just basically want to reduce blocks for a math formula etc you can use procedures to reduce blocks more. I shared some useful block usage in the past, I hope you could decrease your blocks more:

I hope these resources can help you!

I did that already but what i m trying to make doesnt exist (at least so far)

I did that too and thats where i decided to use an extension. Even the procedures where too many and the loading of blocks slow.

You do a great job in the community, you, taifun and many many others and i m really grateful.

Thank you and dont forget me if you come up with anything new that could help me
:wink:

1 Like

Of course! Thanks for your kind words! :blush:

Solution found with the help of
com.google.appinventor.components.runtime.GoogleMap.java Source code
after another 200 pages i read
lol
The Truth Is Out There

Niko

P.S. The thread can now be closed