Extension The operation Text cannot accept the arguments: , [*nothing*] error

Hello,
I try to make an extension which give music artist nane from the file data.
I succed to do this in an android studio sketch,
but when i copy code to have an AI extension i have error:
"The operation Text cannot accept the arguments: , [nothing]"

Here is the code:

Blockquote
package jml.mp3tags;
import android.media.MediaMetadataRetriever;
import 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.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.util.MediaUtil;
import java.io.File;

@DesignerComponent(version = Mp3Tags.VERSION,
description = "obtention des tags d'un mp3" + "jm latour ",
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "icone/music.png")
@SimpleObject(external = true)
public class Mp3Tags extends AndroidNonvisibleComponent implements Component {
private ComponentContainer container;
public static final int VERSION = 1;
public static String fichier="";

//public class MetaExtractActivity extends Activity {
public Mp3Tags(ComponentContainer container) {
    super(container.$form());
    this.container = container;
    //artist(fichier);
}

MediaMetadataRetriever metaRetriever;

@SimpleFunction(description = "return file's artist")
public String artist(String song){
    File file=new File(song);
    String art=song;
    metaRetriever = new MediaMetadataRetriever();
    if (file.exists()) {
        metaRetriever.setDataSource(song);
        try {
            art=metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
            //art="null";
        } catch (Exception e) {
            art="Unknown Artist";
        }
    }else {
        art="file not found";
    }
    return art;
}

}

The problem comes from "art=metaRetriever.extractMetadata" wichc seems put nothing in variable art.
if i code art="null"; in this place code works and return "null"...

What Android OS Version are you running it on?

Also try
if (art == "") {
art = "Unknown Artist";
}

Hello Ken thank you for your answer.

it's not an android version problem, because if the artist tag exists, the return is correct and the extensions works fine.( i have android 9 )

the problem apears when file has no artist tag then the extension return i don't know what !!
for my mind it shoulr return "Unknown Artist" because it should be an error and shoul be cath, but no...it return something, i don't know what , AI call it "[nothing]".

it is not an empty string because your suggestion changes nothing.
i tried to replance "" by "[nothing]" but no changes.

any other idea ?

You are not checking whether art is null or not.

1 Like

vknow360 is right:

I didn't notice the "" around null

Try:

if (art == "" || art == null) {
art = "Unknown Artist";
}

3 Likes

Oh yes ! you are right !
I tried (art=null) which gave me error but i didn't realize i need to write 2 "="
it works better with good synthax !

thanks all !

1 Like

'=' assigns value to a variable while '==' compares values.
Basics of java :wink:

4 Likes