Error in compiling extension in Niotron IDE

I was trying to make an advanced TinyDB extension in Niotron IDE from App Inventor Sources, and when compiling the extension in Niotron IDE, I encountered two errors. I didn’t understand why the errors appeared.

Started Compiling Project TinyDBE
Buildfile: /compiler/android/build.xml

javac:
[mkdir] Created dir: /compiler/android/build/roFHy/classes
[javac] Compiling 1 source file to /compiler/android/build/roFHy/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: Wrote file file:/compiler/android/build/roFHy/classes/simple_components.json
[javac] Note: Wrote file file:/compiler/android/build/roFHy/classes/simple_components.txt
[javac] Note: Wrote file file:/compiler/android/build/roFHy/classes/simple_components_build_info.json
[javac] Note: Wrote file file:/compiler/android/build/roFHy/classes/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/compiler/android/build/roFHy/classes/ComponentsTranslation.java
[javac] /compiler/android/src/roFHy/com/gordonlu/tinydbe/TinyDBE.java:40: error: cannot find symbol
[javac] public class TinyDBE extends AndroidNonvisibleComponent implements Component, Deletable{
[javac] ^
[javac] symbol: class Component
[javac] /compiler/android/src/roFHy/com/gordonlu/tinydbe/TinyDBE.java:40: error: cannot find symbol
[javac] public class TinyDBE extends AndroidNonvisibleComponent implements Component, Deletable{
[javac] ^
[javac] symbol: class Deletable
[javac] 2 errors

This was the source code of the extension.

package com.gordonlu.tinydbe;

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.common.YaVersion;
import com.google.appinventor.components.runtime.errors.YailRuntimeError;
import com.google.appinventor.components.runtime.util.JsonUtil;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;

import org.json.JSONException;

@DesignerComponent(
        version = 1,
        description = "TinyDBE is an enhanced version of TinyDB, with additional blocks.",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "https://docs.google.com/drawings/d/e/2PACX-1vQCI87PHLBF0jb8QWyYmIRQSjjNW3EFXf-qpsWCvBYkUQ9vEgPAB8SpxcMpblxNpbIYrjCjLrRLIU2c/pub?w=16&h=16")


//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class TinyDBE extends AndroidNonvisibleComponent implements Component, Deletable{

    public TinyDBE(ComponentContainer container){
        super(container.$form());
        this.activity = container.$context();
        this.context = container.$context();
        Namespace(DEFAULT_NAMESPACE);
    }

    public static final String DEFAULT_NAMESPACE="TinyDB1";

    private SharedPreferences sharedPreferences;
    private String namespace;

    private Context context;

    private Activity activity;


  @SimpleProperty(description = "Namespace for storing data.", category = PropertyCategory.BEHAVIOR)
    @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = DEFAULT_NAMESPACE)
  public void Namespace(String namespace) {
    this.namespace = namespace;
    sharedPreferences = context.getSharedPreferences(namespace, Context.MODE_PRIVATE);
  }

  @SimpleProperty(description = "Namespace for storing data.")
  public String Namespace() {
    return namespace;
  }

  /**
   * Store the given `valueToStore`{:.variable.block} under the given `tag`{:.text.block}.
   * The storage persists on the phone when the app is restarted.
   *
   * @param tag The tag to use
   * @param valueToStore The value to store. Can be any type of value (e.g.
   * number, text, boolean or list).
   */
  @SimpleFunction(description = "Store the given value under the given tag.  The storage persists "
      + "on the phone when the app is restarted.")
  public void StoreValue(final String tag, final Object valueToStore) {
    final SharedPreferences.Editor sharedPrefsEditor = sharedPreferences.edit();
    try {
      sharedPrefsEditor.putString(tag, JsonUtil.getJsonRepresentation(valueToStore));
      sharedPrefsEditor.commit();
    } catch (JSONException e) {
      throw new YailRuntimeError("Value failed to convert to JSON.", "JSON Creation Error.");
    }
  }

  /**
   * Retrieve the value stored under the given `tag`{:.text.block}.  If there's no such tag, then
   * return `valueIfTagNotThere`{:.variable.block}.
   *
   * @param tag The tag to use
   * @param valueIfTagNotThere The value returned if tag in not in TinyDB
   * @return The value stored under the tag. Can be any type of value (e.g.
   * number, text, boolean or list).
   */
  @SimpleFunction(description = "Retrieve the value stored under the given tag. If there's no "
      + "such tag, then return valueIfTagNotThere.")
  public Object GetValue(final String tag, final Object valueIfTagNotThere) {
    try {
      String value = sharedPreferences.getString(tag, "");
      // If there's no entry with tag as a key then return the empty string.
      //    was  return (value.length() == 0) ? "" : JsonUtil.getObjectFromJson(value);
      return (value.length() == 0) ? valueIfTagNotThere : JsonUtil.getObjectFromJson(value, true);
    } catch (JSONException e) {
      throw new YailRuntimeError("Value failed to convert from JSON.", "JSON Creation Error.");
    }
  }

   /**
   * Return a list of all the tags in the data store.
   *
   * @return a list of all keys.
   */
  @SimpleFunction(description = "Return a list of all the tags in the data store.")
  public Object GetTags() {
    List<String> keyList = new ArrayList<String>();
    Map<String,?> keyValues = sharedPreferences.getAll();
    // here is the simple way to get keys
    keyList.addAll(keyValues.keySet());
    java.util.Collections.sort(keyList);
    return keyList;
  }

  @SimpleFunction(description = "Clears the tags that matches the names in the list.")
  public void ClearTags(final String tags) {
    List<String> keyList = new ArrayList<String>();
    Map<String,?> keyValues = sharedPreferences.getAll();
    // here is the simple way to get keys
    keyList.addAll(keyValues.keySet());
    java.util.Collections.sort(keyList);
    String list = keylist;
      if (!tags.isEmpty()) {
          for (E element : tags) {
              if (list.contains(element)) {
                      final SharedPreferences.Editor sharedPrefsEditor = sharedPreferences.edit();
                      sharedPrefsEditor.remove(element);
                      sharedPrefsEditor.commit();
  }
              }
          }
      }

  /**
   * Clear the entire data store.
   *
   */
  @SimpleFunction(description = "Clear the entire data store.")
  public void ClearAll() {
    final SharedPreferences.Editor sharedPrefsEditor = sharedPreferences.edit();
    sharedPrefsEditor.clear();
    sharedPrefsEditor.commit();
  }

  /**
   * Clear the entry with the given `tag`{:.text.block}.
   *
   * @param tag The tag to remove.
   */
  @SimpleFunction(description = "Clear the entry with the given tag.")
  public void ClearTag(final String tag) {
    final SharedPreferences.Editor sharedPrefsEditor = sharedPreferences.edit();
    sharedPrefsEditor.remove(tag);
    sharedPrefsEditor.commit();
  }

  @Override
  public void onDelete() {
    final SharedPreferences.Editor sharedPrefsEditor = sharedPreferences.edit();
    sharedPrefsEditor.clear();
    sharedPrefsEditor.commit();
  }
}

From the error, it has something to do with implements Component, Deletable, I just want to know how I can fix it.

Can somebody help me?

I don’t think so that there is any requirement or advantage for setting it as final and I think it can create Runtime Error and also remove that implementation and try compiling again

Thank you

I tried it - If I remove the implementation, it will show error that the @Override does not have an implementation.

Ok wait let me read and understand the code

What is the use of this
I haven’t used it anywhere in my extension development life

It’s just to define what sort of property it is, there are APPEARANCE, BEHAVIOUR, and so on. This does not appear in most builders, but for some reason I see developers still add it.

Use it above simple property

I tried, the same errors appear, there are still 2 errors (and only 2 errors) to do with implementing.

I can see that you are not using any library
Can you please show the error screenshot after removing implementation

I added

import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.Deleteable;

and it works, but it has new errors.

image

You are iteating tags list in element and instead of using E use Datatype

1 Like

Thanks. It said it is successful but it did not download the extension.

Started Compiling Project TinyDBE
Buildfile: /compiler/android/build.xml

javac:
[mkdir] Created dir: /compiler/android/build/nLOJd/classes
[javac] Compiling 1 source file to /compiler/android/build/nLOJd/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] Note: Wrote file file:/compiler/android/build/nLOJd/classes/simple_components.json
[javac] Note: Wrote file file:/compiler/android/build/nLOJd/classes/simple_components.txt
[javac] Note: Wrote file file:/compiler/android/build/nLOJd/classes/simple_components_build_info.json
[javac] Note: Wrote file file:/compiler/android/build/nLOJd/classes/AutogeneratedOdeMessages.java
[javac] Note: Wrote file file:/compiler/android/build/nLOJd/classes/ComponentsTranslation.java

process:
[mkdir] Created dir: /compiler/android/out/nLOJd
[mkdir] Created dir: /compiler/android/build/nLOJd/externalComponents
[mkdir] Created dir: /compiler/android/build/nLOJd/externalComponents-classes
[java]
[java] Extensions : Generating extensions

unjarAllExtensionLibraries:

jarAllExtensions:

dexAllExtensions:

extensions:

BUILD SUCCESSFUL
Total time: 1 second

Try compiling again

It still did not download :frowning: . I don’t understand.

I refreshed the browser, it still doesn’t work.

Ok let me try by copying your code
Can I do it

YailRuntimeError can’t be converted into a real YailRuntimeError object.

errors are why probaly