Hello,
in a project, i’m creating an array of arrayLists that i’m filling with integers in a function and then sending through OSC messages.
But if I try to add one of the value to the osc message:
myMessage.add(messages[i].get(j));
it returns the error:
The method add(Object) from the type OscMessage is not visible
if I try to break it down: int val = messages[i].get(j);
I get:
Type mismatch, "java.lang.Object" does not match with "int"
On the other hand, if I test it with instanceof
I find out it’s an integer as expected.
I’m printing the Arraylist in several places and it’s showing expected values…
I’ve tried also to force the object as an integer with int(messages[i].get(j));
but it doesn’t work as well…
I’m totally out of clues… Any hints or similar experience would be appreciated
Here is my full code in case it helps: I’m filling the ArrayLists in synchronized void portraitCourt()
which is called once when synchronized void oscEvent()
receives a message. Osc message is built and sent in synchronized void sendPlaylis()
import netP5.*;
import oscP5.*;
OscP5 oscP5;
NetAddress screen[]; // RPI receiver OSC object
ArrayList[] messages;
String playlist[]; // to load the videos list
String file[];
String RPIs[]; //RPI video players network configs
int type;
int perso;
int intention;
int number;
int endCount = 0; //how many RPIs finished their sequence
void setup(){
playlist = loadStrings("playlist.txt");
RPIs = loadStrings("RPIs.txt");
screen = new NetAddress[RPIs.length];
messages = new ArrayList[RPIs.length];
for(int i=0; i<RPIs.length; i++){
messages[i] = new ArrayList<Integer>();
}
oscP5 = new OscP5(this,8000);
for(int i=0; i<RPIs.length; i++){
String[] infos = split(RPIs[i],"*");
screen[i] = new NetAddress(infos[0],int(infos[1]));
}
}
void draw(){
if(endCount == RPIs.length){
println("everybody's done!");
}
}
/// send all the messages when playlists are generated
synchronized void sendPlaylist(){
for(int i=0; i<RPIs.length; i++){
OscMessage select = new OscMessage("/select");
if(messages[i].get(0) instanceof Integer){
println("it's an integer");
}else{println("it's not!!");}
for(int j=0; j<messages[i].size(); j++){
println("all values are " + messages[i].get(j));
//int val = messages[i].get(j); // Doesn't work
//select.add(messages[i].get(j)); // Doesn't work
//oscP5.send(select,screen[i]);
}
}
synchronized void portraitCourt(String perso, int nbPortrait, int screenNum){
ArrayList<String> portrait = new ArrayList<String>();
for(int i=0; i<playlist.length; i++){
String[] video = split(playlist[i],"_");
if(video[1].equals(perso)==true && video[0].equals("E")==true){
println("found match");
portrait.add(i + "*" + playlist[i]); // adds selected videos in arraylist (index*name)
}
}
println("portrait " + portrait);
messages[screenNum].clear();
for(int i=0; i<nbPortrait; i++){
int r = int(random(0, portrait.size()-1));
String[] rank = split(portrait.get(r),"*"); // can be skipped if video name removed from arraylist
messages[screenNum].add(int(rank[0]));
}
println("message is " + messages[screenNum] + " stop");
}
synchronized void oscEvent(OscMessage theOscMessage){
if(theOscMessage.checkAddrPattern("/end")==true){
endCount =+ 1;
}
if(theOscMessage.checkAddrPattern("/play")==true){
println("message received");
portraitCourt("2",3,0);
sendPlaylist();
}
}