Error in my java code

Hey all I am new to java and extension development , Today while I was trying to make small extension for learning purpose I got this error while compiling my extension

I am using appybuilder code editor

my code


 /**  ~~~~~
 * Created with the AppyBuilder Code Editor.
 * This is a template for basic Extension.
 * Modify this template to customize your extension.
 *
 * **** NOTE: DO NOT use a package name. 
 * **** The package name will be created for you automatically.
 * **** Adding a package name will cause a compile error
 */
import android.content.Context;
import android.util.Log;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.common.ComponentCategory;

@DesignerComponent(version = 1,  description = "This Extension was created with the AppyBuilder Code Editor.<br>" + 
                   "Create your own here:<br><a href='https://editor.appybuilder.com' target='_blank'>https://editor.appybuilder.com</a><br>",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,   iconName = "http://appyBuilder.com/extensions/icons/extension.png")
@SimpleObject(external = true)

public class Testok extends AndroidNonvisibleComponent {
    private ComponentContainer container;
    /**
     * @param container container, component will be placed in
     */
    public Testok(ComponentContainer container) {
        super(container.$form());
        this.container = container;
    }
  
    @SimpleFunction(description = "Stores a value in TinyDB")
    public void StoreValue(final String tag, final String valueToStore) {
        TinyDB tinyDB = new TinyDB(container);
        tinyDB.StoreValue(tag, valueToStore);
    }
  
    @SimpleFunction(description = "Retrieves value of a tag")
    public Object GetValue(final String tag, final Object valueIfTagNotThere) {
        TinyDB tinyDB = new TinyDB(container);
        return tinyDB.GetValue(tag, valueIfTagNotThere);
    }
  
}
@SimpleProperty(description"Returns true if 20 is greater than 18")
   if (20 > 18) {
      System.out.println("20 is greater than 18");
   }

I just added this rest all was there

@SimpleProperty(description"Returns true if 20 is greater than 18")
   if (20 > 18) {
      System.out.println("20 is greater than 18");
   }

The error that is coming

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/yash_sehgal_2017/Testok/Testok.java:48: error: ')' expected
    [javac] @SimpleProperty(description"Returns true if 20 is greater than 18")
    [javac]                            ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:48: error: class, interface, or enum expected
    [javac] @SimpleProperty(description"Returns true if 20 is greater than 18")
    [javac]                                                                   ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]    ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]       ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]        ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]           ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]             ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]               ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]                 ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:50: error: class, interface, or enum expected
    [javac]       System.out.println("20 is greater than 18");
    [javac]       ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:51: error: class, interface, or enum expected
    [javac]    }
    [javac]    ^
    [javac] 11 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: 3 seconds
inventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]             ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]               ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:49: error: class, interface, or enum expected
    [javac]    if (20 > 18) {
    [javac]                 ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:50: error: class, interface, or enum expected
    [javac]       System.out.println("20 is greater than 18");
    [javac]       ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/yash_sehgal_2017/Testok/Testok.java:51: error: class, interface, or enum expected
    [javac]    }
    [javac]    ^
    [javac] 11 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: 3 seconds

You have wrote the code incorrectly. Even it is the first step of a learner that you missed.

It should be :

@SimpleProperty(description"Returns true if 20 is greater than 18")
public boolean IsGreater(){
   if (20 > 18) {
      return true;
   }else
       return false;
}

You can check the above default code for functions.

2 Likes

Don’t worry everyone makes mistakes.
Just the extent is problem.

public boolean Is20GreaterThan18(){
return 20 > 18;
}
3 Likes

thanks @vknow360 and @iamwsumit for your help :smiley:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.