Getting error in extension building

so, i have to use what

I have tried to use code from vknow360 and it still raises the error

You need to ask him/developer of the code.

I am confused, what should I do, :pleading_face:

I am also confused every time :sweat_smile: :upside_down_face:

What is "YOUR_CONTEXT" in the code ? You might want to pass the application context there.

The developer from where you got the code wanted to give hint "YOUR_CONTEXT", what to pass as argument.

Here is how to get context

2 Likes

still not work :pleading_face:
but I have added what you said.
Please Help Me :pray:

My Code :

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.widget.Toast;

//External


@DesignerComponent(version = 1,
    category = ComponentCategory.EXTENSION,
    description = "Made my YOU",
    nonVisible = true,
    iconName = "https://icon-icons.com/icons2/1808/PNG/48/code_115247.png")

@SimpleObject(external = true)

public class ExtensionTemplate extends AndroidNonvisibleComponent {

public ExtensionTemplate(ComponentContainer container) {
    super(container.$form());
}

//Write you're code here
   @SimpleFunction(description = "Show toast message")
    public void ShowToastMessage(String value) {
       //YOUR ACTIVITY HERE
      Toast.makeText(container.$context(), value, Toast.LENGTH_SHORT).show();
    }
   

}

Error :

Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml

extensions:

clean:

init:

common_CommonUtils:

init:

CommonUtils:

common_CommonVersion:

init:

CommonVersion:
     [exec] Result: 128
     [exec] Result: 128

CopyToRunLibDir:

components_AndroidRuntime:

init:

CommonConstants:
    [javac] Compiling 6 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
    [javac] 1 warning

HtmlEntities:
    [javac] Compiling 1 source file to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/HtmlEntities
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
    [javac] 1 warning

common_CommonVersion:

init:

CommonVersion:
     [exec] Result: 128
     [exec] Result: 128

AndroidRuntime:
    [javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/salmanappinventor/ExtensionTemplate/ExtensionTemplate.java:37: error: cannot find symbol
    [javac]       Toast.makeText(container.$context(), value, Toast.LENGTH_SHORT).show();
    [javac]                      ^
    [javac]   symbol:   variable container
    [javac]   location: class ExtensionTemplate
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 1 error
    [javac] 1 warning

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.

Total time: 7 seconds
/HtmlEntities.jar

common_CommonVersion:

init:

CommonVersion:
     [exec] Result: 128
     [exec] Result: 128

AndroidRuntime:
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
    [javac] Compiling 332 source files to /projects/goldv2/appinventor-sources/appinventor/components/build/classes/AndroidRuntime
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/salmanappinventor/ExtensionTemplate/ExtensionTemplate.java:37: error: cannot find symbol
    [javac]       Toast.makeText(container.$context(), value, Toast.LENGTH_SHORT).show();
    [javac]                      ^
    [javac]   symbol:   variable container
    [javac]   location: class ExtensionTemplate
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] 1 error
    [javac] 1 warning

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:35: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:372: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/components/build.xml:141: The following error occurred while executing this line:
/projects/goldv2/appinventor-sources/appinventor/build-common.xml:118: Compile failed; see the compiler error output for details.

Total time: 7 seconds

I think colin tree builder uses extension templete and appybuilder code editor uses appinventor-sources to compile

Using appinventor-sources is the best if you are unsure that the extension template support. FYI.

Please help me, I think my code is wrong

Define the container variable inside your inner class :point_up: :

private ComponentContainer container;

And then set it to the extension container here, so you can use it any where in your project:

this.container = container;
1 Like

okay i will try, thank you :kissing_heart:

do you mean like this :

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.widget.Toast;

//External


@DesignerComponent(version = 1,
    category = ComponentCategory.EXTENSION,
    description = "Made my YOU",
    nonVisible = true,
    iconName = "https://icon-icons.com/icons2/1808/PNG/48/code_115247.png")

@SimpleObject(external = true)

public class ExtensionTemplate extends AndroidNonvisibleComponent {
  
  private ComponentContainer container; 
  this.container = container;

/*public ExtensionTemplate(ComponentContainer container) {
    super(container.$form());*/
}

//Write you're code here
   @SimpleFunction(description = "Show toast message")
    public void ShowToastMessage(String value) {
       //YOUR ACTIVITY HERE
      Toast.makeText(container.$context(), value, Toast.LENGTH_SHORT).show();
    }
   

}

this.container = container should be in

public (class_name) (...){
super(container.$form());
this.container = container;
}
1 Like

This should be under this line

As the extension container variable is defined there.

Like This :

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import android.widget.Toast;

//External


@DesignerComponent(version = 1,
    category = ComponentCategory.EXTENSION,
    description = "Made my YOU",
    nonVisible = true,
    iconName = "https://icon-icons.com/icons2/1808/PNG/48/code_115247.png")

@SimpleObject(external = true)

public class ExtensionTemplate extends AndroidNonvisibleComponent {
  
  public ExtensionTemplate(ComponentContainer container) {
  super(container.$form());
  this.container = container;
}

//Write you're code here
   @SimpleFunction(description = "Show toast message")
    public void ShowToastMessage(String value) {
       //YOUR ACTIVITY HERE
      Toast.makeText(container.$context(), value, Toast.LENGTH_SHORT).show();
    }
   

}

Correct. :+1:

You need to define the container variable as i said:

or i don't see it :sweat_smile:

1 Like

where should I put it

Inside your class, under this line