NPM extension question

Hello,
I've been looking at some tutorials...
Thank you very much for your help, I have added what you have told me, but I keep getting another error.

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
    */
    package com.meulencv.Internet_speed;

import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;

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.
" +
"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 Internet_speed extends AndroidNonvisibleComponent {
private ComponentContainer container;
/**
* @param container container, component will be placed in
*/
public Internet_speed(ComponentContainer container) {
super(container.$form());
this.container = container;
}

@SimpleFunction(description = "")
public int GetWifiSpeed () {
WifiManager wifiManager = container.$context().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null) {
Integer linkSpeed = wifiInfo.getLinkSpeed();
}
return linkSpeed;

}
}

Error:

Error: Failed execute ant extensions: Command executing error occured: code(1)stdout:
Buildfile: %SERVER_WORKSPACE%/appinventor/build.xml

extensions:

clean:

init:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/build/components
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build/classes
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/reports
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/reports/raw
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/reports/html

CommonConstants:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build/classes/CommonConstants
[javac] Compiling 7 source files to %SERVER_WORKSPACE%/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 %SERVER_WORKSPACE%/appinventor/components/build/classes/CommonConstants/com/google/appinventor/components/common/package-info.class
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/build/components/CommonConstants.jar
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/build/components/CommonConstants-gwt.jar

HtmlEntities:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build/classes/HtmlEntities
[javac] Compiling 1 source file to %SERVER_WORKSPACE%/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: %SERVER_WORKSPACE%/appinventor/components/build/HtmlEntities.jar

common_CommonVersion:

init:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/build/common
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/build
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/build/classes
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/reports
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/reports/raw
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/reports/html

CommonVersion:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/build/classes/CommonVersion
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/common/build/src/com/google/appinventor/common/version
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/common/build/src/com/google/appinventor/common/version
[javac] Compiling 3 source files to %SERVER_WORKSPACE%/appinventor/common/build/classes/CommonVersion
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] 1 warning
[javac] Creating empty %SERVER_WORKSPACE%/appinventor/common/build/classes/CommonVersion/com/google/appinventor/common/version/package-info.class
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/build/common/CommonVersion.jar
[jar] Building jar: %SERVER_WORKSPACE%/appinventor/build/common/CommonVersion-gwt.jar

CopyComponentLibraries:
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps/armeabi-v7a
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps/arm64-v8a
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps/x86_64
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 57 files to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 2 files to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps
[copy] Copying 1 file to %SERVER_WORKSPACE%/appinventor/build/components/deps

AndroidRuntime:
[mkdir] Created dir: %SERVER_WORKSPACE%/appinventor/components/build/classes/AndroidRuntime
[javac] Compiling 266 source files to %SERVER_WORKSPACE%/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] %SERVER_WORKSPACE%/appinventor/components/src/com/meulencv/Internet_speed/Internet_speed.java:41: error: incompatible types: Object cannot be converted to WifiManager
[javac] WifiManager wifiManager = container.$context().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
[javac] ^
[javac] %SERVER_WORKSPACE%/appinventor/components/src/com/meulencv/Internet_speed/Internet_speed.java:46: error: cannot find symbol
[javac] return linkSpeed;
[javac] ^
[javac] symbol: variable linkSpeed
[javac] location: class Internet_speed
[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] 2 errors
[javac] 1 warning

stderr:

BUILD FAILED
%SERVER_WORKSPACE%/appinventor/build.xml:42: The following error occurred while executing this line:
%SERVER_WORKSPACE%/appinventor/components/build.xml:193: The following error occurred while executing this line:
%SERVER_WORKSPACE%/appinventor/build-common.xml:125: Compile failed; see the compiler error output for details.

Total time: 14 seconds

can you help me, please?


import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;

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 = "WRITE DISCRIPTION OF YOUR EXTENSION",
category = ComponentCategory.EXTENSION,
nonVisible = true, 
iconName = "ICON URL OF YOUR EXTENSION")
@SimpleObject(external = true)
public class Internet_speed extends AndroidNonvisibleComponent {

private ComponentContainer container;

public Internet_speed(ComponentContainer container) {
    super(container.$form());
    this.container = container;
}

@SimpleFunction(description = "DESCRIPTION OF METHOD.")
public int GetWifiSpeed () {
    WifiManager wifiManager = (WifiManager) container.$context().getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int linkSpeed = 0;
    if (wifiInfo != null) {
        int linkSpeed = wifiInfo.getLinkSpeed();
    }
    return linkSpeed;
}
}

1 Like

please start with the basic extension because extension development is not easy for a beginner. you are doing some basic mistake like

Type Casting Error

Use Primitive DataTypes

Implement Perfect Logic

what happened in the case of wifiInfo = null in that case local variable linkSpeed is not defined so that you can't return it. see into your error

2 Likes

I strongly recommend you please start with basic and learn some basic core concept of JAVA because we have lots of hope from you.

every extension developer made something new which helps community so best of luck for extension development.

please fell free to ask question

1 Like

Thanks for all :slight_smile:

Oh sorry that was my mistake, I forgot to change the integer :sweat_smile:

1 Like

Thank you for fixing the code but I suggest you to don't need to add this line :

 int linkSpeed = 0;

because it's not important, it's like you initialized the integer twice

1 Like

no my dear friend in case of wifiInfo = null linkSpeed is not defined.

2 Likes

OH, okay i will check

1 Like

see this error

2 Likes

oh yeah i think you are right but it still error

1 Like

show me error

1 Like

OKay i got it

1 Like

its still error because you initialize it on the code

1 Like

you should do like this :

package com.salman.test;

import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;

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 Testing extends AndroidNonvisibleComponent {
    private ComponentContainer container;
    private int linkSpeed = 0;

    public Testing(ComponentContainer container) {
        super(container.$form());
        this.container = container;
    }
  
    @SimpleFunction(description = "DESCRIPTION OF METHOD.")
    public int GetWifiSpeed () {
       WifiManager wifiManager = (WifiManager) container.$context().getSystemService(Context.WIFI_SERVICE);
       WifiInfo wifiInfo = wifiManager.getConnectionInfo();
       
       if (wifiInfo != null) {
           int linkSpeed = wifiInfo.getLinkSpeed();
       }
       return linkSpeed;
    }
  
}

So the problem is you can't initialize the int in the code, you have to initialize the code outside the function. Works 100%

2 Likes

no it not required
according to me why we need to create one instance variable of object because we need only value at runtime after method execution we are not interested in linkSpeed but if we create instance variable then it will stored into heap memory.

1 Like

then why don't you try compiling the code you edited? I've tried compiling the code you edited and it doesn't work.

and the code that I have edited works 100%

1 Like

Are you sure Salman? That would just return the value 0.

1 Like

i think im sure sir :sweat_smile:
please guide me if I am wrong

1 Like

please follow the naming conventions

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like