# selectInput() + loadTable()

**URL:** https://discourse.processing.org/t/selectinput-loadtable/42966
**Category:** Coding Questions
**Created:** [October 14, 2023, 1:05am UTC](https://discourse.processing.org/t/selectinput-loadtable/42966 "2023-10-14T01:05:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![xxxdiegoxxx](https://avatars.discourse-cdn.com/v4/letter/x/87869e/32.png) [@xxxdiegoxxx](https://discourse.processing.org/u/xxxdiegoxxx)
#### Post date: [October 14, 2023, 1:05am UTC](https://discourse.processing.org/t/selectinput-loadtable/42966/1 "2023-10-14T01:05:12Z")

</div>

Hi! im on a sketch in which i have some classes and one of then should take a .csv file and create some lists.

ive set a global string to receive the selectInput() result and asked the class to generate the table using the string as a parameter. im receiving a NullPointerException.

my guess is that loadTable(filename, “header”) is looking for the file inside the data folder but as its receiving a whole path wherever the user chose a file from (like “c:\users\name\file.csv”), it wont work.

heres a sample of the code:

```auto
String pathSelection;

tracker myTracker;

void setup(){
  //size(1900, 1000);

  myTracker = new tracker();
  myTracker.getFile();
}

void draw(){}

class tracker{
  //tracker class constructor goes here and some other parameters

void getList(){
    selectInput("Select a encounter to load", "fileSelected");
    Table eventTable = loadTable(pathSelection, "header");
    for(TableRow row : eventTable.rows()){
      //variables are created here to receive the rows from the csv file and process whats needed.
    }
  }
}

```

so, if its the way im guessing, how can i implement a way to the user select a file from anywhere and it generates a table?

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [October 14, 2023, 8:32am UTC](https://discourse.processing.org/t/selectinput-loadtable/42966/2 "2023-10-14T08:32:53Z")

</div>

Hi @xxxdiegoxxx,

Here an example which loads from a selected path…  
Hope that helps …

Cheers  
— mnse

```auto
/*
---------------------------------------------
Example Table (ie. D:\Downloads\dummy.csv)
---------------------------------------------
Forename,Surname,Age
John,Doe,30
Jane,Doe,29
L'il,Doe,4
---------------------------------------------
*/
Tracker myTracker;

void setup() {
  getSurface().setVisible(false);
  myTracker = new Tracker();
  myTracker.chooseList();
}

public class Tracker {
  void chooseList() {
    selectInput("Select a encounter to load", "fileSelected", null, this);
  }

  public void fileSelected(File selection) {
    if (selection == null) {
      println("Window was closed or the user hit cancel.");
    } else {
      println("User selected " + selection.getAbsolutePath());
      try {
        Table myTable = new Table(selection, "header");
        myTable.print();
      }
      catch(Exception e) {
        println("Error loading table: " + e.getMessage());
      }
    }
  } 
}

```

> console output ie.

```auto
User selected D:\Downloads\dummy.csv
Forename Surname Age
John Doe 30
Jane Doe 29
L'il Doe 4

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [October 14, 2023, 8:55am UTC](https://discourse.processing.org/t/selectinput-loadtable/42966/3 "2023-10-14T08:55:16Z")

</div>

> [@xxxdiegoxxx](#):
>
> ```auto
> selectInput("Select a encounter to load", "fileSelected");
>   
> 
> ```

In this line you tell processing that a function  
fileSelected gets called when the dialog is closed.

Do you have this function?

Processing doesn’t wait for selectInput() to finish.

So you can’t have the loadTable where you have it now.

Also, check whether the path is still null

See reference and the example given

---

<div class="post-metadata">

### Author: ![xxxdiegoxxx](https://avatars.discourse-cdn.com/v4/letter/x/87869e/32.png) [@xxxdiegoxxx](https://discourse.processing.org/u/xxxdiegoxxx)
#### Post date: [October 17, 2023, 11:47am UTC](https://discourse.processing.org/t/selectinput-loadtable/42966/4 "2023-10-17T11:47:45Z")

</div>

@Chrisir: yeah, i forgot to paste the function. theres one, i copied it from the reference.

@mnse: it worked just fine, thank you! im new to programming and processing helps a lot. im yet to understand “public”, “static” and other types of function declarations; im guessing thats what went wrong, but it will be a task for another day.

now i got to transform my cvs into nice “artistic-like” graphics with motion and other stuff.

thank you so much you both for your time and your help!
