Help me make my first extension

I have made my first extension in Appybulder Code Editor. But it is pointing out some bugs I have attached both the code and errors while compiling. Please help me complete it.

import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

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)
@UsesPermissions(permissionNames = "android.permission.WRITE_EXTERNAL_STORAGE, android.permission.READ_EXTERNAL_STORAGE")
public class Demo1 extends AndroidNonvisibleComponent {
    private ComponentContainer container;
    /**
     * @param container container, component will be placed in
     */
    public Demo1(ComponentContainer container) {
        super(container.$form());
        this.container = container;
    }
  
   @SimpleFunction (description = "magic")
	public String Manipulation(String image,String nameoffile) {  	
  System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
		String file = image;
      String final = ""/"+nameoffile+".png"";
      Mat src = Imgcodecs.imread(file,0);
      Mat dst = new Mat();
      Imgproc.adaptiveThreshold(src, dst, 125, Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY, 11, 12);
      Imgcodecs.imwrite(final, dst);
      return final;
    }
    } ```



[details="Bug Report"]
Buildfile: /projects/goldv2/appinventor-sources/appinventor/build.xml

extensions:

clean:
   [delete] Deleting directory /projects/goldv2/appinventor-sources/appinventor/build/components

BUILD FAILED
/projects/goldv2/appinventor-sources/appinventor/build.xml:34: The following error    [delete] Deleting directory /projects/goldv2/appinventor-sources/appinventor/components/reports

init:

common_CommonUtils:

init:

CommonUtils:

common_CommonVersion:

init:

CommonVersion:
     [exec] Result: 128
     [exec] Result: 128

CopyToRunLibDir:

components_AndroidRuntime:

init:
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/build/components
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/reports
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/reports/raw
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/reports/html

CommonConstants:
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/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
    [javac] Creating empty /projects/goldv2/appinventor-sources/appinventor/components/build/classes/CommonConstants/com/google/appinventor/components/common/package-info.class
      [jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/build/components/CommonConstants.jar
      [jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/build/components/CommonConstants-gwt.jar

HtmlEntities:
    [mkdir] Created dir: /projects/goldv2/appinventor-sources/appinventor/components/build/classes/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
      [jar] Building jar: /projects/goldv2/appinventor-sources/appinventor/components/build/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/ravigargrud/Demo1/Demo1.java:44: error: not a statement
    [javac]       String final = ""/"+nameoffile+".png"";
    [javac]       ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:44: error: ';' expected
    [javac]       String final = ""/"+nameoffile+".png"";
    [javac]             ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:44: error: illegal start of type
    [javac]       String final = ""/"+nameoffile+".png"";
    [javac]                    ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:44: error: ';' expected
    [javac]       String final = ""/"+nameoffile+".png"";
    [javac]                     ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:44: error: illegal start of expression
    [javac]       String final = ""/"+nameoffile+".png"";
    [javac]                        ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:44: error: ';' expected
    [javac]       String final = ""/"+nameoffile+".png"";
    [javac]                         ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:44: error: illegal start of expression
    [javac]       String final = ""/"+nameoffile+".png"";
    [javac]                                       ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:44: error: ';' expected
    [javac]       String final = ""/"+nameoffile+".png"";
    [javac]                                           ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:48: error: illegal start of expression
    [javac]       Imgcodecs.imwrite(final, dst);
    [javac]                         ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:48: error: ';' expected
    [javac]       Imgcodecs.imwrite(final, dst);
    [javac]                              ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:48: error: not a statement
    [javac]       Imgcodecs.imwrite(final, dst);
    [javac]                                ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:48: error: ';' expected
    [javac]       Imgcodecs.imwrite(final, dst);
    [javac]                                   ^
    [javac] /projects/goldv2/appinventor-sources/appinventor/components/src/com/appybuilder/ravigargrud/Demo1/Demo1.java:49: error: illegal start of expression
    [javac]       return final;
    [javac]              ^
    [javac] 13 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: 2 seconds
[/details]
1 Like

I think you are not familiar with Java till yet.
So I suggest you to learn Java first.

1 Like

Yes, I know the basics but haven’t coded for last 2 years. So obviously I would need to practice to be familiar with Java again. :grin:

Still, I request, if you can help.

I’m getting this error repeatedly @vknow360
error: package org.opencv.core does not exist

You are using external lib which neither includes in build path nor you can add it using Appy Builder.
Use extension template instead.

1 Like

Ok! Thanks for your help can you please clarify what at do you mean by?

Use this lightweight ‘offline’ ide:

2 Likes

Thanks for help. I will try and tell you.

  1. You typed that wrong:

    String final = ""/"+nameoffile+".png"";
    

    Needs to be:

    String final = "/" + nameoffile + ".png";
    
  2. Also final is a reserved word in Java. Reserved words are used by programming language itself. You can’t use it to name your variable.

2 Likes

I have changed all of that but it will still not work as

See here how to add external lib:

Above topic is related to ai sources but method is same also in template.
But in template just add jar to deps dir.

1 Like

Can you please help me? I dont know what I need to do.

Sure.

I am unable to install add environment variable for ant, even after adding when I check in Command Prompt it shows no such command ant -version

Have you installed Ant?
Have you correctly set path of Ant?

1 Like

Make sure that you have edited path and ANT_HOME in system variables

1 Like

How?:relieved: I just unzipped the file and placed it in C drive then the gave that path in variable setting.

Sorry…I mean downloaded.

Then problem can be there.

Capture3

You want to edit path