hello there I am here today cause I need help creating an extension with Niotron IDE
my problem is :
that when I complete my extension code and while testing it gives me an error message "undefined" from the companion
this extension about checking email validation by using API
this is the code
code
package com.koder.email.check.disp.valid.dev;
import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.json.JSONObject;
@DesignerComponent(
version = 1,
description = "",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "")
@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")
public class Email_Chekcer extends AndroidNonvisibleComponent {
//Activity and Context
private Context context;
private Activity activity;
private String xRapidAPIKey;
private boolean valid;
private boolean disposable;
public Email_Chekcer(ComponentContainer container){
super(container.$form());
this.activity = container.$context();
this.context = container.$context();
}
@SimpleFunction(description = "Sample Function Generated by Niotron")
public void TestFunction(String domain, String xRapidAPIKey) throws IOException {
this.xRapidAPIKey = xRapidAPIKey;
URL url = new URL("https://mailcheck.p.rapidapi.com/?domain=" + domain);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("X-RapidAPI-Host", "mailcheck.p.rapidapi.com");
connection.setRequestProperty("X-RapidAPI-Key", xRapidAPIKey);
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
//Getting the response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//Parsing the response
JSONObject jsonResponse = new JSONObject(response.toString());
valid = jsonResponse.getBoolean("valid");
disposable = jsonResponse.getBoolean("disposable");
EventDispatcher.dispatchEvent(this, "TestEvent", valid, disposable);
}
@SimpleProperty(description = "Valid value from API")
public boolean isValid() {
return valid;
}
@SimpleProperty(description = "Disposable value from API")
public boolean isDisposable() {
return disposable;
}
@SimpleEvent(description = "Test Event Generated by Niotron")
public void TestEvent(boolean valid, boolean disposable) {
EventDispatcher.dispatchEvent(this, "TestEvent", valid, disposable);
}
}
unfortunately, the same error exists.
this is API key you can test it: 43ae771ac0msh7c7a2c1131746d6p14aaa8jsn0db2e7e754e9
and replace the domain with virtual or real email
package com.koder.email.check.disp.valid.dev;
import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.util.AsynchUtil;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
@DesignerComponent(
version = 1,
description = "",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "")
@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")
public class Email_Checker extends AndroidNonvisibleComponent {
//Activity and Context
private Context context;
private Activity activity;
private String xRapidAPIKey;
private boolean valid;
private boolean disposable;
public Email_Checker(ComponentContainer container){
super(container.$form());
this.activity = container.$context();
this.context = container.$context();
}
@SimpleFunction(description = "Checks the validity and disposable status of the provided email address")
public class Email_Checker extends AndroidNonvisibleComponent {
//Activity and Context
private Context context;
private Activity activity;
private String xRapidAPIKey;
private boolean valid;
private boolean disposable;
public Email_Checker(ComponentContainer container){
super(container.$form());
this.activity = container.$context();
this.context = container.$context();
}
@SimpleFunction(description = "Checks the validity and disposable status of the provided email address")
public void CheckEmail(final String email, final String xRapidAPIKey) throws IOException {
AsynchUtil.runAsynchronously(new Runnable () {
@Override
public void run() {
try {
String encodedEmail = URLEncoder.encode(email, "UTF-8");
URL url = new URL("https://mailcheck.p.rapidapi.com/check?email=" + encodedEmail);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("X-RapidAPI-Host", "mailcheck.p.rapidapi.com");
connection.setRequestProperty("X-RapidAPI-Key", xRapidAPIKey);
connection.setRequestMethod("GET");
//Getting the response
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
final StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
JSONObject jsonResponse = new JSONObject(response.toString());
valid = jsonResponse.getBoolean("valid");
disposable = jsonResponse.getBoolean("disposable");
activity.runOnUiThread(new Runnable () {
@Override
public void run() {
EmailChecked(valid, disposable);
}
});
} catch (final Exception e) {
activity.runOnUiThread(new Runnable () {
@Override
public void run() {
e.printStackTrace();
}
});
}
}
});
}
@SimpleEvent(description = "Event triggered when email is checked")
public void EmailChecked(boolean valid, boolean disposable) {
EventDispatcher.dispatchEvent(this, "EmailChecked", valid, disposable);
}
@SimpleProperty(description = "Valid value from API")
public boolean isValid() {
return valid;
}
@SimpleProperty(description = "Disposable value from API")
public boolean isDisposable() {
return disposable;
}
}
but it gives me this message after trying to compile
error
Started Compiling Project Email_Chekcer
Buildfile: /compiler/android/build.xml
javac:
[mkdir] Created dir: /compiler/android/build/jWpQp/classes
[javac] Compiling 1 source file to /compiler/android/build/jWpQp/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /compiler/android/src/jWpQp/com/koder/email/check/disp/valid/dev/Email_Chekcer.java:121: error: reached end of file while parsing
[javac] }
[javac] ^
[javac] 1 error
[javac] 1 warning