# Tabulated Data won't load (null pointer exception error)

**URL:** <https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315>\
**Category:** Coding Questions\
**Created:** [October 10, 2018, 7:23am UTC](https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315 "2018-10-10T07:23:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicole\_C\_973](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@Nicole\_C\_973](https://discourse.processing.org/u/Nicole_C_973)\
**Post date:** [October 10, 2018, 7:23am UTC](https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315/1 "2018-10-10T07:23:24Z")

</div>

Hi guys

I’ve managed to create an animation that works (reading strings from tabulated data)! Woo hoo.

Except… I’ve made a few small changes to my tabular data, have re-saved it as a tsv file again (same name as before so should be no issues there?) and now my animation won’t work.

I’ve tried dragging and dropping it onto the code, accepted it as a new version and still nothing.

Can anyone give me some pointers on why it might not be recognizing the new tsv file?

Thanks in advance.

Nicole

Here is my code in case this gives any hints as to what I’ve done):

```auto
//final project - working file //<>// //<>//

color[] rainbow = {#169499, #BF0C2B, #F14C13, #FFD418, #03A63C, #04117B, #400A34, #02173E, #421F02, #0B080B, #F2055C, #D9D0B1, #F8A602, #F1F0F1};
String[] palette = {"aqua", "red", "orange", "yellow", "green", "blue", "purple", "indigo", "brown", "black", "pink", "grey", "grey", "white"};

int y = 600;
int dy = 0;
Bubble[][] myBubbles; // Array of bubble types
int revisedCount;

Table colorscultures; 
int rowCount;
color bubbleColour = 0;// Bubble colours
int culturesSize = 8;//Header row
PImage bg;

void setup() {
  size(1000, 600);
  bg = loadImage("blue_sky.jpg");
  image (bg, 0, 0);
  smooth();
  colorscultures = loadTable("colorscultures.tsv");
  rowCount = colorscultures.getRowCount();
  

  myBubbles = new Bubble[culturesSize][rowCount];
  float myY = 0;
  revisedCount = 0;
  for (int z = 0; z < rowCount; z += 1) {
    String colour = colorscultures.getString(z, 0);
    String american = colorscultures.getString(z, 1);
    String european = colorscultures.getString(z, 2);
    String indian_hindu = colorscultures.getString(z, 3);
    String muslim = colorscultures.getString(z, 4);
    String asian = colorscultures.getString(z, 5);
    String chinese = colorscultures.getString(z, 6);
    String japanese = colorscultures.getString(z, 7);
    String native_american = colorscultures.getString(z, 8);
        
    //Settings (spacing) for where to display each bubble (layed out in columns) 
    setCultureBubbles(z, 100, myY, colour, american, 0);
    setCultureBubbles(z, 200, myY, colour, european, 1);
    setCultureBubbles(z, 300, myY, colour, indian_hindu, 2);
    setCultureBubbles(z, 400, myY, colour, muslim, 3);
    setCultureBubbles(z, 500, myY, colour, asian, 4);
    setCultureBubbles(z, 600, myY, colour, chinese, 5);
    setCultureBubbles(z, 700, myY, colour, japanese, 6);
    setCultureBubbles(z, 800, myY, colour, native_american, 7);

    //Space between bubbles as they come up
    myY += 80;
    //revisedCount += 1;
    //}
  }
  //rowCount = revisedCount;

  //myBubbles[0] = new Bubble(75, 0, 50, "H");
  //myBubbles[1] = new Bubble(25, 0 - 30, 50, "S");
  //myBubbles[2] = new Bubble(25, 0 - 60, 50, "S");
}

//What info to grab in order to create bubble when it reads data (x, y, colour, culture header, content)
void setCultureBubbles(int z, float myX, float myY, String colour, String culture, int cultureIndex)
{
  boolean display = true;
  if (culture.length() == 0)
  {
    display = false;
    culture = "";
  }

  if (colour.length() != 0)
  {
    bubbleColour = getColour(colour);
  }
  myBubbles[cultureIndex][z] = new Bubble(random(10,990), myY, 70, culture, display, bubbleColour);
  println(z + " Colour:" + bubbleColour);
}

//Get colour for bubble
color getColour(String colour) {
  //int myColour = 0;
  for (int count=0; count < palette.length; count += 1)
  {
    if (palette[count].equals(colour.toLowerCase())) 
    {
      return rainbow[count];
    }
  }
  return 0;
}

void draw() {
  background (0);
  image (bg, 0, 0);
  smooth();
  //stroke(#BF0C2B); //
  //strokeWeight(1); // 
  //ellipse (100, y, 50, 50);
  //ellipse (25, y + 50, 50, 50);
  for (int count = 1; count < rowCount; count += 1)
  {
    for (int culturesCount = 0; culturesCount < culturesSize; culturesCount += 1)
    {
      myBubbles[culturesCount][count].display(y);
    }
    //myBubbles[2].display(y, "B");
    //println(" Y: " + myBubbles[count].totalY);
  }
  println(" finish");
  //ellipse (80, 80, 50, 50);
  y = y + dy;
  if (y <= 600) {
    dy = -3;
  }
  //if(y > 0) {
  // dy = 1;
  //}
}

// This simple Bubble class draws a circle to the window 
// and displays a text label when the mouse hovers.
class Bubble {
  float x, y;
  float diameter;
  String name;
  float totalY;
  boolean display;
  color colour;

  boolean over = false;

  // Create the Bubble
  Bubble(float tempX, float tempY, float tempD, String s, boolean myDisplay, color myColour) {
    x = tempX;
    y = tempY;
    diameter = tempD;
    name = s;
    display = myDisplay;
    colour = myColour;
  }

  // Display the Bubble
  void display(float myY) {
    if (display)
    {
      //stroke(0,255,0);
      //strokeWeight(2);

      //color(myColour);
      fill(colour); //fill colour of ellipse
      totalY = y + myY;
      //fill(colour);
      
      stroke(#F1F0F1); //outside line of ellipse
      strokeWeight(2);//for ellipse
      textAlign(CENTER);
      text(name, x, totalY);
      
      ellipse(x, totalY, diameter, diameter);
      x = x + random(-1, 1);
      y--;

      
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 10, 2018, 9:10am UTC](https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315/2 "2018-10-10T09:10:18Z")

</div>

could you setup a pure filetest?  
like a new “project” but where you copy the  
**/data/colorscultures.tsv**  
directory and file to.  
and run some code like

```auto
Table table;
int i, k, trows, tcols;

void setup() {

  table = loadTable("colorscultures.tsv"); // "test.tsv" // "test.tsv" , "tsv" // "test.tsv" , "header , tsv"
  trows=table.getRowCount();
  tcols=table.getColumnCount();

  println(trows + " rows/lines in table "); //(? - header ?)
  println(tcols + " cols in table");
  println("header: ");
  for ( i =0; i < tcols; i++) {
    println("col: "+i+" "+ table.getColumnTitle(i));
  }

  for ( k =0; k < trows; k++) {
    for ( i =0; i < tcols; i++) {
      println("row: "+k+" col: "+i+" string: "+table.getString(k, i));
    }
  }
}

/*
 in subdir
 /data/test.tsv
 make / find ( use [Tab] )
 
 a b c
 1 2 3
 
 */

```

but actually i must admit that here PC win7 / processing 3.4 /  
CSV file worked, TSV file NOT // only could read ONE column //  
until i rechecked by editor ( notepad++ / blank operation ) to replace space with Tab

---

<div class="post-metadata">

**Author:** ![Nicole\_C\_973](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@Nicole\_C\_973](https://discourse.processing.org/u/Nicole_C_973)\
**Post date:** [October 10, 2018, 8:49pm UTC](https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315/3 "2018-10-10T20:49:53Z")

</div>

Thanks kll - Ill give that a try and have noted that maybe I need to change to csv file. TSV format might be the issue.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [October 10, 2018, 10:29pm UTC](https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315/4 "2018-10-10T22:29:38Z")

</div>

> [@Nicole\_C\_973](#):
>
> TSV format might be the issue.

> [@kll](#):
>
> until i rechecked by editor ( notepad++ / blank operation ) to replace space with Tab

As long as the delimiter used in a “.tsv” file is actually a TAB `'\t'` character, and not a regular space `' '`, **loadTable()** should work for TSV the same as for CSV: 📁

> **[loadTable() / Reference](https://processing.org/reference/loadTable_.html)**
>
> Reads the contents of a file or URL and creates a Table object with its values. If a file is specified, it must be located in the sketch's "data" folder. The filename parameter can also be a URL to a …

Here’s some sketch which loads a “.tsv” w/ “header”: 🕶

- [Why isn't initializing ArrayList size working? - Processing 2.x and 3.x Forum](http://Forum.Processing.org/two/discussion/24562/why-isn-t-initializing-arraylist-size-working#Item_31)

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [October 11, 2018, 12:00am UTC](https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315/5 "2018-10-11T00:00:57Z")

</div>

You should double check your .tsv file again, as it could have been corrupted or unintentionally changed.

NullPointedException usually appears when you are trying to access data that doesn’t exist, so it could be the data your trying to get from the table.

---

<div class="post-metadata">

**Author:** ![Nicole\_C\_973](https://avatars.discourse-cdn.com/v4/letter/n/a88e4f/32.png) [@Nicole\_C\_973](https://discourse.processing.org/u/Nicole_C_973)\
**Post date:** [October 11, 2018, 1:07am UTC](https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315/6 "2018-10-11T01:07:11Z")

</div>

Thanks Sarah

I ended up creating a new spreadsheet as I think you were right, data on last one was corrupted, and it works again!

On another note- using code below- do you know how I can:

1. Change bubble size to fit width of text (have watched lots of tutorials and I am still missing something)

2. Get my text colour to change? I’ve tried tweaking each part and so far it stays same colour as bubble

3. MousePressed code to make bubble disappear when mouse clicks it and leaves just the text

Help on any of these would be greatly appreciated! None of the tutorials I’ve found are an exact fit to my code.

Nicole

---

<div class="post-metadata">

**Author:** ![Sarah](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sarah/32/1675_2.png) [@Sarah](https://discourse.processing.org/u/Sarah)\
**Post date:** [October 11, 2018, 1:30am UTC](https://discourse.processing.org/t/tabulated-data-wont-load-null-pointer-exception-error/4315/7 "2018-10-11T01:30:36Z")

</div>

You can change the size of the bubble by adjusting the diameter based on how long the text is using `.length()`. ([https://processing.org/reference/String\_length\_.html](https://processing.org/reference/String_length_.html))

If you want to change the color of a `text();` you can use `fill();` like you would with anything else. Right now both the text and ellipse are under `fill(colour);` so they would both be filled the same.

To find if the mouse has clicked the ellipse, you have to perform a point-circle collision and have a `boolean` which turns false when the mouse is colliding with the circle and `mousePressed`.

It could look something like this:

```auto
if(displayBubble) {
  fill(<bubble color>);
  ...Display bubble code...
}
fill(<text color>);
...Display text code...

if(dist(mouseX, mouseY, circleX, circleY) < diameter/2 && mousePressed) {
  displayBubble = false;
}

```
