Instantiate variable of outside class

GoodMorning, I have a question about of usage this parameter in contructor class.
My minimal code is:

class MediaLoad {
  File file;
  Movie mov;
  MediaLoad (File _file) {
    _file = file;
    mov = new Movie(this,file.getAbsolutePath());
MediaLoad ml;

when I digit the line:
mov = new Movie(this,file.getAbsolutePath());
the red allert compare with:
The constructor “Movie(MediaLoad, String)” does not exist

In the Object documentation is explained the this parameter is parent and the error confirm that.
Is a way to instantiate my mov variable inside another class?

Thanks !

1 Like
  • Java’s keyword this is of the same datatype as the class it’s being used.
  • Movie’s constructor expects datatype PApplet as its 1st parameter, not a MediaLoad.
  • A better approach would be to request an already instantiated Movie instance in place of a File for your class MediaLoad’s constructor.

Thank You GoToLoop, Very fast response!
I try your way…

With GoToLoop suggestion i found the way:


class MediaLoad {

  ArrayList<File> mediaList = new ArrayList<File>();
  ArrayList<File> fileArray; // array con i file dell'articolo selezionato
  ArrayList<Movie> videoList; // array con i video caricati

  MediaLoad(ArrayList<File> _mediaList) {
    mediaList = _mediaList;

  void load() {
    boolean videoTrovato = false;
    fileArray = new ArrayList<File>();
    for (File file : mediaList) {
      if (!file.getName().contains(".thum") && !file.isDirectory()) {
        if ( // carico i video in array
          || file.getName().contains(".mp4")
          || file.getName().contains(".avi")) {
          videoTrovato = true;
        } // fine if
      } // fine if non thumb
    } // fine for mediaList
    if (videoTrovato) {
      loadMovie(fileArray, videoList);
    } // fine if videoTrovato
  } // fine load;
} // fine class

// -------------------------------------------------------------------------

void loadMovie(ArrayList<File> fileList, ArrayList<Movie> movList) {
  for (File file : fileList) {
    movList.add(new Movie(this, file.getAbsolutePath()));

the code is only an extract of my MediaLoad class
Have a Nice Coding Guys !!!

1 Like