(solved)Error in math extensions

welcome,
i am on the way to develop a block like this
pi.JPG

and i coded

package edu.hifiapps.Mathy;
import com.google.appinventor.components.annotations.;
import com.google.appinventor.components.runtime.
;
import com.google.appinventor.components.common.*;
import java.lang.Math;

@DesignerComponent(version = 1, description = "this extension is used to make math easy electrobot999@gmail.com ",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "https://i.ibb.co/P443L1V/myAvatar.png")

@SimpleObject(external = true)
public class Mathy extends AndroidNonvisibleComponent implements Component{
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Mathy(ComponentContainer container) {
super(container.$form());
this.container = container;
}

@SimpleFunction(description = "")
public void pi() {
//YOUR ACTIVITY HERE
return Math.PI;
}
}

got error

Picked up _JAVA_OPTIONS: -Xmx1024m
Buildfile: C:\Users\GOD\appinventor-sources\appinventor\build.xml
extensions:
clean:
[delete] Deleting directory C:\Users\GOD\appinventor-sources\appinventor\build\components
[delete] Deleting directory C:\Users\GOD\appinventor-sources\appinventor\components\build
[delete] Deleting directory C:\Users\GOD\appinventor-sources\appinventor\components\reports
common_CommonVersion:
init:
CommonVersion:
init:
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\build\components
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\build
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\build\classes
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\reports
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\reports\raw
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\reports\html
HtmlEntities:
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\HtmlEntities
[javac] Compiling 1 source file to C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\HtmlEntities
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[jar] Building jar: C:\Users\GOD\appinventor-sources\appinventor\components\build\HtmlEntities.jar
Barcode:
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\Barcode
[javac] Compiling 40 source files to C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\Barcode
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[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 warning
[jar] Building jar: C:\Users\GOD\appinventor-sources\appinventor\build\components\deps\Barcode.jar
CopyComponentLibraries:
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps\armeabi-v7a
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps\arm64-v8a
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps\x86_64
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 59 files to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 2 files to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
[copy] Copying 1 file to C:\Users\GOD\appinventor-sources\appinventor\build\components\deps
common_CommonUtils:
init:
CommonUtils:
CommonConstants:
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\CommonConstants
[javac] Compiling 7 source files to C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\CommonConstants
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[javac] Creating empty C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\CommonConstants\com\google\appinventor\components\common\package-info.class
[jar] Building jar: C:\Users\GOD\appinventor-sources\appinventor\build\components\CommonConstants.jar
[jar] Building jar: C:\Users\GOD\appinventor-sources\appinventor\build\components\CommonConstants-gwt.jar
AnnotationProcessors:
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\AnnotationProcessors
[javac] Compiling 41 source files to C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\AnnotationProcessors
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: C:\Users\GOD\appinventor-sources\appinventor\components\src\com\google\appinventor\components\scripts\ComponentProcessor.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: C:\Users\GOD\appinventor-sources\appinventor\components\src\com\google\appinventor\components\scripts\ComponentProcessor.java uses unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 warning
[javac] Creating empty C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\AnnotationProcessors\com\google\appinventor\components\annotations\androidmanifest\package-info.class
[javac] Creating empty C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\AnnotationProcessors\com\google\appinventor\components\annotations\package-info.class
[javac] Creating empty C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\AnnotationProcessors\com\google\appinventor\components\scripts\package-info.class
[copy] Copying 22 files to C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\AnnotationProcessors
[jar] Building jar: C:\Users\GOD\appinventor-sources\appinventor\components\build\AnnotationProcessors.jar
AndroidRuntime.uptodate:
AndroidRuntime:
[mkdir] Created dir: C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\AndroidRuntime
[javac] Compiling 295 source files to C:\Users\GOD\appinventor-sources\appinventor\components\build\classes\AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] warning: In component Mathy, method pi is missing a description.
[javac] Note: Wrote file file:/C:/Users/GOD/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/simple_components.json
[javac] warning: In component Mathy, method pi is missing a description.
[javac] Note: Wrote file file:/C:/Users/GOD/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/simple_components.txt
[javac] Note: Wrote file file:/C:/Users/GOD/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/simple_components_build_info.json
[javac] warning: In component Mathy, method pi is missing a description.
[javac] Note: Wrote file file:/C:/Users/GOD/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/C:/Users/GOD/appinventor-sources/appinventor/components/build/classes/AndroidRuntime/ComponentsTranslation.java
[javac] warning: In component Mathy, method pi is missing a description.
[javac] C:\Users\GOD\appinventor-
sources\appinventor\components\src\edu\hifiapps\Mathy\Mathy.java:27: error: incompatible types: unexpected return value
[javac] return Math.PI;
[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] 1 error
[javac] 4 warnings
BUILD FAILED
C:\Users\GOD\appinventor-sources\appinventor\build.xml:46: The following error occurred while executing this line:
C:\Users\GOD\appinventor-sources\appinventor\components\build.xml:215: The following error occurred while executing this line:
C:\Users\GOD\appinventor-sources\appinventor\build-common.xml:125: Compile failed; see the compiler error output for details.
Total time: 17 seconds

now i have no idea how to solve please help in code

you cannot use public void to return data, so make like this :

@SimpleFunction(description = "")
public int Pi() {
   return Math.PI;
}
1 Like

did that but still

Try this :

    @SimpleFunction(description = "")
    public String Pi() {
       return Math.PI;
    }

and this :

    @SimpleFunction(description = "")
    public Object Pi() {
       return Math.PI;
    }

i found i got it

In Maths PI = 3.14...

this is float value so you need to return it into float type like this,

       @SimpleFunction(description = "")
       public float Pi() {
          return (float)Math.PI;
       }
1 Like

do you have any documentation about that?

may be but really as it said it is a "double" value

i did as
@SimpleFunction(description = "")
public double Pi() {
return (float)Math.PI;
}

1 Like

thats why error mentioned -double to int

1 Like

This one is not possible

correct code is

@SimpleFunction(description = "")
public double Pi() {
   return (double)Math.PI;
}

i think you are right @HIFI_APPS

1 Like

any way thanks both i got this idea from you both
@preetvadaliya,@salman_dev

First you need to learn about data types some keyword and OOPS concepts

I think @HIFI_APPS is right because I saw this code :

@SimpleFunction (description = "Calculates the area of Circle. Input should be in same unit.")
  public double AreaOfCircle ( double radius )
  {
return (double) (Math.PI * (radius * radius));
  }

i only know three types int,string,float now double where can i learn all

yes it worked

there are many types of datatypes in java

  1. Primitive datatypes
    Boolean
    char
    byte
    short
    int
    long
    float
    double

  2. Non-primitive datatypes
    String
    objects
    etc..

this is proof that @HIFI_APPS is right

i remember all this in childhood except short,objects

i don't have any idea to mark solution to anyone,both helped me in this if i marked 1 other will be sad so let it be without a mark