Context error while develope extension

(Jitendra Modi) #1

@SimpleFunction(description = “Simple app source checker”)
public boolean isInstalledFromPlayStore(Context context) { }

while creating extension, On above line getting bellow error, please guide if any have solution for it.

AndroidRuntime:
[javac] Compiling 1 source file to /home/Makeroid/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[jar] Building jar: /home/Makeroid/appinventor/build/components/AndroidRuntime.jar

ComponentProcessingLib:

common_CommonUtils:

init:

CommonUtils:

AnnotationProcessors:

JsonComponentDescription:
[mkdir] Created dir: /home/Makeroid/appinventor/components/build/classes/JsonComponentDescription
[javac] Compiling 292 source files to /home/Makeroid/appinventor/components/build/classes/JsonComponentDescription
[javac] warning: No SupportedSourceVersion annotation found on com.google.appinventor.components.scripts.ComponentDescriptorGenerator, returning RELEASE_6.
[javac] warning: Supported source version ‘RELEASE_6’ from annotation processor ‘com.google.appinventor.components.scripts.ComponentDescriptorGenerator’ less than -source ‘1.8’
[javac]
[javac]
[javac] An annotation processor threw an uncaught exception.
[javac] Consult the following stack trace for details.
[javac] java.lang.RuntimeException: Cannot convert Java type ‘android.content.Context’ to Yail type
[javac] at com.google.appinventor.components.scripts.ComponentProcessor.javaTypeToYailType(ComponentProcessor.java:1478)
[javac] at com.google.appinventor.components.scripts.ComponentDescriptorGenerator.outputParameters(ComponentDescriptorGenerator.java:245)
[javac] at com.google.appinventor.components.scripts.ComponentDescriptorGenerator.outputBlockMethod(ComponentDescriptorGenerator.java:224)
[javac] at com.google.appinventor.components.scripts.ComponentDescriptorGenerator.outputComponent(ComponentDescriptorGenerator.java:127)
[javac] at com.google.appinventor.components.scripts.ComponentDescriptorGenerator.outputResults(ComponentDescriptorGenerator.java:263)
[javac] at com.google.appinventor.components.scripts.ComponentProcessor.process(ComponentProcessor.java:811)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
[javac] at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
[javac] at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
[javac] at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:523)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:381)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:370)
[javac] at com.sun.tools.javac.main.Main.compile(Main.java:361)
[javac] at com.sun.tools.javac.Main.compile(Main.java:56)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[javac] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:58)
[javac] at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1160)
[javac] at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:936)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:435)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
[javac] at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
[javac] at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
[javac] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
[javac] at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
[javac] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[javac] at java.lang.reflect.Method.invoke(Method.java:498)
[javac] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
[javac] at org.apache.tools.ant.Task.perform(Task.java:348)
[javac] at org.apache.tools.ant.Target.execute(Target.java:435)
[javac] at org.apache.tools.ant.Target.performTasks(Target.java:456)
[javac] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
[javac] at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
[javac] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[javac] at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
[javac] at org.apache.tools.ant.Main.runBuild(Main.java:853)
[javac] at org.apache.tools.ant.Main.startAnt(Main.java:235)
[javac] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
[javac] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

0 Likes

(Sander Jochems) #2

You cant use the Context class in the function. You have to declare a variable of it and use it in the function

2 Likes

(Jitendra Modi) #3

Please anybody share me a sample code to get context in extension.

0 Likes

(Philipp Lang) #4

there is a example code on in the community, i read that yesterday.

0 Likes

(Jitendra Modi) #5

Please share me a link.

0 Likes

(MeteorCoder) #6

Alright

public class Hosts extends AndroidNonvisibleComponent implements Component {
    private ComponentContainer container;
    // Add this => private Context context;

    public Hosts(ComponentContainer container) {
      super(container.$form());
      this.container = container;
      this.context = container.$context();
    }

You’ll see :arrow_double_up: in the extension towards the beginnings except change Hosts to your filename, minus the .java

1 Like

(Jitendra Modi) #7

Thank you very much for reply, it really helps a lot.

0 Likes

(MeteorCoder) #8

You’re welcome :blush: glad to help. To make things found easier, click the 3 horizontal dots on my post and select the check mark then. In return for the favor I did for you (give you the solution).

1 Like

(system) closed #9

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

0 Likes