error: constructor AndroidNonvisibleComponent in class AndroidNonvisibleComponent cannot be applied to given types

151 views
Skip to first unread message

Arne Mailand

unread,
Oct 1, 2016, 5:34:41 PM10/1/16
to App Inventor Open Source Development
Dear friends,

I am kinda new to all this... trying to make an AI extension from a code which I made in Android Studio and successfully tested on my mobile android phone. Here is what I got so far:


package com.google.appinventor.components.runtime;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.common.YaVersion;
import com.google.appinventor.components.runtime.util.AsynchUtil;
import com.google.appinventor.components.runtime.util.ErrorMessages;
import com.google.appinventor.components.runtime.util.FileUtil;
import com.google.appinventor.components.runtime.Form;
import com.google.appinventor.components.runtime.ReplForm;

import android.app.Activity;
import android.content.Context;
import android.os.Environment;
import android.util.Log;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.Socket;

@DesignerComponent(version = YaVersion.FILE_COMPONENT_VERSION,
        description = "Meine erste Extension",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "images/extension.png")
@SimpleObject(external = true)
@UsesPermissions(permissionNames = "android.permission.WRITE_EXTERNAL_STORAGE, android.permission.INTERNET, android.permission.READ_EXTERNAL_STORAGE")
public class Filet extends AndroidNonvisibleComponent implements Component {


    @SimpleFunction(description = "Funktionsbeschreibung hier")
    public void filet(Void... voids) {

        Socket socket;

        File file = new File(Environment.getExternalStorageDirectory(), "bild.jpg");

        try {
            socket = new Socket("192.168.178.32", 80);
        } catch (IOException e) {
            e.printStackTrace();
        }


        byte[] bytes = new byte[(int) file.length()];
        try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
            BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());

            bis.read(bytes, 0, bytes.length);

            bos.write(bytes, 0, bytes.length);
            bos.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
//            bis.close();
//            bos.close();
        }

    }
}


As I try to compile, I get this error:

    [javac] /Users/XXXXXX/Documents/mai/appinventor/components/src/com/google/appinventor/components/runtime/Filet.java:46: error: constructor AndroidNonvisibleComponent in class AndroidNonvisibleComponent cannot be applied to given types;

    [javac] public class Filet extends AndroidNonvisibleComponent implements Component {

    [javac]        ^

    [javac]   required: Form

    [javac]   found: no arguments

    [javac]   reason: actual and formal argument lists differ in length

    [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



Sounds like a simple error which should be able get solved easily, but I can't handle it. Anyone got some ideas?


Thanks

Arne Mailand

unread,
Oct 1, 2016, 6:36:23 PM10/1/16
to App Inventor Open Source Development
Well I guess there is some issue with the constructor of the superclass. This seems to need a Form object. I now changed the code in a way how the other components are programmed:

....
public class Filet extends AndroidNonvisibleComponent implements Component{

    public void Filet(ComponentContainer container){
        super(container.$form());
    }

    @SimpleFunction(description = "Funktionsbeschreibung hier")
    public void Filet2(Void... voids){
        Socket socket;

        File file = new File(Environment.getExternalStorageDirectory(), "bild.jpg");
...


This should be the proper way, right? But I still get the same error. And a new one:

[javac] /Users/kirikiri3/Documents/mai/appinventor/components/src/com/google/appinventor/components/runtime/Filet.java:46: error: constructor AndroidNonvisibleComponent in class AndroidNonvisibleComponent cannot be applied to given types;

    [javac] public class Filet extends AndroidNonvisibleComponent implements Component{

    [javac]        ^

    [javac]   required: Form

    [javac]   found: no arguments

    [javac]   reason: actual and formal argument lists differ in length

    [javac] /Users/kirikiri3/Documents/mai/appinventor/components/src/com/google/appinventor/components/runtime/Filet.java:49: error: call to super must be first statement in constructor

    [javac]         super(container.$form());





Any ideas?

Evan Patton

unread,
Oct 1, 2016, 7:01:20 PM10/1/16
to App Inventor Open Source Development
Hi Arne,

The constructor of a class does not take a return type. By specifying public void Fillet(ComponentContainer container) you have declared a public member function that returns nothing (void) called Fillet. Removing the void return type will make Fillet become a constructor.

Evan

Arne Mailand

unread,
Oct 1, 2016, 9:20:49 PM10/1/16
to App Inventor Open Source Development
That made it. After fixing that and some other issues, the code seems to be fine now. Thanks a lot!

Arne Mailand

unread,
Oct 2, 2016, 10:01:27 AM10/2/16
to App Inventor Open Source Development
Oh well, it seems like I was too hasty. After removing that void, I do not get any compiler errors anymore but now I get build errors from ant:

...

BUILD FAILED

/Users/kirikiri3/Documents/mai/appinventor/build.xml:36: The following error occurred while executing this line:

/Users/kirikiri3/Documents/mai/appinventor/components/build.xml:343: The following error occurred while executing this line:

/Users/kirikiri3/Documents/mai/appinventor/components/build.xml:230: Compile failed; see the compiler error output for details.


I can't exactly tell which lines these refer to, but I think these output lines are referred to the errors:


...

   [depend] Looking for [Ljava.lang.Void;

Couldn't load Resource [Ljava/lang/Void;.class

...


...

    [javac] java.lang.RuntimeException: Cannot convert Java type 'java.lang.Void[]' to Yail type

...


I guess it has something to do with the method of that component, which I defined like this:


    @SimpleFunction(description = "Funktionsbeschreibung hier")

   
public void Filet2(Void... voids){

       
Socket socket;

       
File file = new File(Environment.getExternalStorageDirectory(), "bild.jpg");


       
byte[] bytes = new byte[(int) file.length()];

       
try {

            socket
= new Socket("192.168.178.32", 80);

           
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));


           
BufferedOutputStream bos = new BufferedOutputStream(socket.getOutputStream());

            bis
.read(bytes, 0, bytes.length);

            bos
.write(bytes, 0, bytes.length);

            bos
.flush();


            socket
.close();


       
} catch (FileNotFoundException e) {

            e
.printStackTrace();

       
} catch (IOException e) {

            e
.printStackTrace();

       
} finally {

//            bis.close();

//            bos.close();

       
}

   
}



So I guess the problem is this:

    public void Filet2(Void... voids){


Do you guys agree? How do I have to write this? The method is just supposed to do a job and there is no need to return anything. It also works with fixed parameters, so I thought everything has to be void... but... well do you say?

Jos Flores

unread,
Oct 2, 2016, 10:12:11 AM10/2/16
to app-inventor-open-source-dev
Why are you passing a number of Voids as a parameter to your method?
if you don't need parameters, just define it without them:

public void Filet2(){ YOUR_CODE_HERE; }



cheers,
José
> --
> You received this message because you are subscribed to the Google Groups
> "App Inventor Open Source Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to app-inventor-open-so...@googlegroups.com.
> To post to this group, send email to
> app-inventor-o...@googlegroups.com.
> Visit this group at
> https://groups.google.com/group/app-inventor-open-source-dev.
> For more options, visit https://groups.google.com/d/optout.

Arne Mailand

unread,
Oct 2, 2016, 2:02:18 PM10/2/16
to App Inventor Open Source Development
Dohh, I am so dumb. Big big thanks, José!

The reason I inserted this was that I needed to do this when I worked with AsyncTask and Android Studio (I can't quite remember why, I think I got compiler errors when I left the parameter field blank).

I will now implement the extension and start testing it... And I can smell the next troubles coming up already (It would be too nice if this would work on the fly)... So I'm pretty sure you guys will hear from me very soon ;-)

Have a nice time until then,

Arne
Reply all
Reply to author
Forward
0 new messages