Cannot convert Java type 'android.content.Context' to Yail type

I’m working on a very plain extension for now.
This is the code:

package net.ontstd.cachetools;

import android.app.Activity;
import android.content.*;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.ComponentCategory;
import java.io.File;

@DesignerComponent(version = 1,  description = "This Extension was created with the AppyBuilder Code Editor.<br>" +
                   "Create your own here:<br><a href='https://editor.appybuilder.com' target='_blank'>https://editor.appybuilder.com</a><br>",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,   iconName = "http://appyBuilder.com/extensions/icons/extension.png")
@SimpleObject(external = true)
public class CacheTools extends AndroidNonvisibleComponent {

    public Context context;

    private ComponentContainer container;
    /**
     * @param container container, component will be placed in
     */
    public CacheTools(ComponentContainer container) {
        super(container.$form());
        this.container = container;
        context = (Context) container.$context();
    }

    @SimpleFunction(description = "Retrieves value of a tag")
    public Object CacheDirectory(Context context) {
      File file = this.context.getExternalFilesDir(null);
      return file.toString();
    }
}

and this is the log:

...
    [javac] An annotation processor threw an uncaught exception.
    [javac] Consult the following stack trace for details.
    [javac] java.lang.IllegalArgumentException: Cannot convert Java type 'android.content.Context' to Yail type
...

The full log is here:
https://pastebin.com/en1MM4rC

I did find this question by Diego on StackOverflow but I have no idea how to implement it in my code

Help is appreciated

EDIT: A reference for my code is here java - context.getExternalFilesDir(null) is null - Stack Overflow

Error says it all.
You can’t pass java types as parameter in extensions.
Either change it to object or create a new method (without annotation )and add your code there.

Thanks for your reply, I’ll try it.

Which Is Answered By Taifun

2 Likes