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,
I am also confused every time
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
still not work
but I have added what you said.
Please Help Me
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 :
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;
okay i will try, thank you
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;
}
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.
You need to define the container variable as i said:
or i don't see it
where should I put it
Inside your class, under this line