Error in creating gradient extension

I am creating a simple gradient extension and I found some error
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/farazfiroz2472/Gradient/Gradient.java:48: error: cannot find symbol
[javac] View view = component.getview();
[javac] ^
[javac] symbol: method getview()
[javac] location: variable component of type AndroidViewComponent
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/farazfiroz2472/Gradient/Gradient.java:68: error: incompatible types: unexpected return value
[javac] return GradientDrawable.Orientation.TOP_BOTTOM;
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/farazfiroz2472/Gradient/Gradient.java:73: error: incompatible types: unexpected return value
[javac] return GradientDrawable.Orientation.BOTTOM_TOP;
[javac] ^
[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] 3 errors
[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
472/Gradient/Gradient.java:48: error: cannot find symbol
[javac] View view = component.getview();
[javac] ^
[javac] symbol: method getview()
[javac] location: variable component of type AndroidViewComponent
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/farazfiroz2472/Gradient/Gradient.java:68: error: incompatible types: unexpected return value
[javac] return GradientDrawable.Orientation.TOP_BOTTOM;
[javac] ^
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/farazfiroz2472/Gradient/Gradient.java:73: error: incompatible types: unexpected return value
[javac] return GradientDrawable.Orientation.BOTTOM_TOP;
[javac] ^
[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] 3 errors
[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

My Code

import android.content.Context;
import android.util.Log;
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.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.view.View;

@DesignerComponent(version = 1, description = "This Extension was created with the AppyBuilder Code Editor.
" +
"Create your own here:
https://editor.appybuilder.com
",
category = ComponentCategory.EXTENSION,
nonVisible = true, iconName = "http://appyBuilder.com/extensions/icons/extension.png")
@SimpleObject(external = true)
public class Gradient extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Gradient(ComponentContainer container) {
super(container.$form());
this.container = container;
}

@SimpleFunction
public void SetGradient(AndroidViewComponent component, Object orientation, int color1, int color2) {
try {
View view = component.getview();

GradientDrawable gradientDrawable = new GradientDrawable(
        (GradientDrawable.Orientation) orientation,
        new int[] {color1,color2}); 

 view.setBackground(gradientDrawable);
} 
   catch(Exception e) {
    ErrorOccured(e.getMessage());
}

}

@SimpleEvent
public void ErrorOccured(String error) {
EventDispatcher.dispatchEvent(this, "ErrorOccured", error);
}

@SimpleProperty
public void TopToBottom() {
return GradientDrawable.Orientation.TOP_BOTTOM;
}

@SimpleProperty
public void BottomToTop() {
return GradientDrawable.Orientation.BOTTOM_TOP;
}

@SimpleProperty
public Object LeftToRight() {
return GradientDrawable.Orientation.LEFT_RIGHT;
}

@SimpleProperty
public Object RightToLeft() {
return GradientDrawable.Orientation.RIGHT_LEFT;
}

@SimpleProperty
public Object BottomLeftToTopRight() {
return GradientDrawable.Orientation.BL_TR;
}

@SimpleProperty
public Object TopRightToBottomLeft() {
return GradientDrawable.Orientation.TR_BL;
}

@SimpleProperty
public Object TopLeftToBottomRight() {
return GradientDrawable.Orientation.TL_BR;
}

@SimpleProperty
public Object BottomRightToTopLeft() {
return GradientDrawable.Orientation.BR_TL;
}

@SimpleFunction
public int ParseColor(String color) {
return Color.parseColor(color);
}
}

Use a Java IDE.

I do not understand what you say

Instead of creating an extension in the AppyBuilder editor, use the recommended AI2 environment.

What I need to use instead of appybuilder editor

It looks as if the appybuilder did not see this import:
import android.view.View;

http://kio4.com/appinventor/125B_extensiones_crear_i.htm

Simply send me what is error in this and what I use on error place

It should be getView()

Is there only one error

@vknow360 I set it to getView() is there more error

IF we all will do everything to help you, what will you yourself learn,

Recommendations :

  1. Learn Java
  2. Download a good IDE (Preferred : Intellij)
  3. Use Appinventor sources/ Extension Template/ Rush , Appybuilder Editor sources are very much deprecated.
  4. Start Building from basic extensions
  5. Try to solve errors yourself mostly, if you fail to solve, then ask here, (Errors teach you many things)

This is my first extension and I try to solve this but I do not understand what is this 2 error
[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/farazfiroz2472/Gradient/Gradient.java:68: error: incompatible types: unexpected return value
[javac] return GradientDrawable.Orientation.TOP_BOTTOM;
[javac] ^

[javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/farazfiroz2472/Gradient/Gradient.java:73: error: incompatible types: unexpected return value
[javac] return GradientDrawable.Orientation.BOTTOM_TOP;
[javac] ^

Appybuilder Editor can give very weird errors, you can use extension template / Rush

Well no one is going to help you in creating a whole extension.

3 Likes

here you used void change it to Object

1 Like

These are the basics.

2 Likes

Hi @Faraz_Firoz as @Know_About_IT commented I would suggest to learn a few things.
Java and basics of Annotations and Classes before starting to develop more complex extensions..
for example start learning by creating extensions that uses Integers or Strings

As my fist extension I made a extension that could return a list of links present in a given sentence

Also I would suggest not to use Appybuilder IDE instead something like extension-template or Appinventor sources or Rush
Extension template is way faster than Appinventor sources as it only compiles the extension files and Appinventor sources also compiles the components present in the components folder.

  1. https://github.com/mit-cml/appinventor-extensions (Extension Template)
  2. https://github.com/mit-cml/appinventor-sources (Appinventor Sources)
  3. Rush • A new and improved way of building extensions (Rush)

And for the IDE I will suggest to install VSCode as its suited for begginers and has mostly all functions that you can think of.

2 Likes

Thanks a lot lot lot to all of you

3 Likes

Welcome! Hope it helped and don't take my words harshly :slight_smile:

1 Like

No problem, Thanks for advicing me

3 Likes