Getting error in extension building

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

Put it above/under the methods...

You should learn java basics first :wink:

Like This Sir

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) {
  private 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();
    }
   

}

Move this before this line, and not under:

Like This Sir :

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;
  
  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();
}
   

}
1 Like

Yes.

I have both :sweat_smile: extension templete for compile extension and sources for personal builder

1 Like

Wow this is Like a dream :star_struck: :star_struck: :star_struck: :star_struck: :star_struck:
Thank you very much @MohamedTamer
Thank you very much @WatermelonIce
And thanks for the others who have helped me

3 Likes

Sir, I want to ask Can this code be used in all extensions? :pray:

  private ComponentContainer container;
  
  public ExtensionTemplate(ComponentContainer container) {
  super(container.$form());
  this.container = container;

This code can be used in all extensions, but you just need to change the class name, as per as your project name, or you will get an error.
This one:

okay i got it, thanks sir

1 Like
package com.extension.Toast1.xoma;


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;

//External
import android.widget.Toast;
import android.content.Context;

@DesignerComponent(version = 1,
   category = ComponentCategory.EXTENSION,
   description = "Simple show toast",
   nonVisible = true,
   iconName = "https://community.appinventor.mit.edu/user_avatar/community.appinventor.mit.edu/kumaraswamy_b.g/32/13770_2.png")

@SimpleObject(external = true)

public class SimpleToast extends AndroidNonvisibleComponent {

private ComponentContainer container;
private Context context;

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

@SimpleFunction(description = "Show toast")
public void ShowToast(String message) {
    Toast.makeText(container.$context(),message,Toast.LENGTH_SHORT).show();
}
}

This is working for me.

1 Like