I’m trying to run some of the sketches from “Rapid Android Development” by Daniel Sauter, one of the books recommended on the “Processing for Android” site (Processing for Android), but I’m not having much luck. I suspect it’s because the book is about 10 years old, and a lot of things have changed since it was written.
For example, here’s a fairly simple example (DataReadGroceries.pde) that reads a text file and displays the data:
Table groceries;
void setup() {
// groceries = new Table(this,"groceries.txt");
groceries = loadTable("groceries.txt", "header");
textSize(24);
rectMode(CENTER);
textAlign(CENTER,CENTER);
noStroke();
noLoop();
background(0);
int count = groceries.getRowCount();
for (int row=1; row<count; row++) {
float rowHeight = height / count;
String amount = groceries.getString(row,0);
String unit = groceries.getString(row,1);
String item = groceries.getString(row,2);
if (groceries.getString(row,3).equals("store")) {
fill(color(255,110,50));
} else if (groceries.getString(row,3).equals("market")) {
fill(color(50,220,255));
} else {
fill(127);
}
rect(width/2,rowHeight/2,width,rowHeight);
fill(255);
text(amount+" "+unit+" "+item,width/2,rowHeight/2);
translate(0,rowHeight);
}
}
I changed one line to use loadTable() instead of Table() because the original code seemed to be broken, but I’m still getting an error, which I don’t understand. I thought it might be a permissions issue, although I’ve set “Read_External_Storage” on. Do I need to request some other permission, or is there some other problem?
Here’s the error I’m getting:
FATAL EXCEPTION: Animation Thread
Process: processing.test.datareadgroceries, PID: 15396
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
at processing.test.datareadgroceries.DataReadGroceries.setup(DataReadGroceries.java:40)
at processing.core.PApplet.handleDraw(PApplet.java:1878)
at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:478)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:518)
I suspect I may be wasting my time trying to run any of the sketches in a book that’s 10 years old. If someone can recommend another book that deals specifically with Processing for Android (as opposed to Android Studio), I’d appreciate it.