We are about to switch to a new forum software. Until then we have removed the registration on this forum.
need your help, gyus
inb4 i know that code is huge pile of bs but i need it to work
catching a lot of errors trying to pass lorem array into load.dissasemble2array
main
int lngth = 10000;
int scaleX = 5;
int scaleY = 2;
String fileName = new String();
String[] lorem = new String[lngth];
int[][] endArray = new int[lngth][10];
int[][] smoothArray = new int[lngth][10];
drawGraph graph;
fileLoad load;
void setup() {
noLoop();
size(1800, 600);
graph = new drawGraph();
selectInput("Select a file to graph: ", "fileSelected");
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
exit();
} else {
println(selection.getAbsolutePath());
fileName = selection.getAbsolutePath();
println(fileName);
lorem = loadStrings(fileName);
endArray = load.disassemble2array(lorem);
smoothArray = load.smoothen(endArray);
}
}
void draw() {
background(0);
stroke(50);
fill(255);
for (int i = 0; i < height; i = i+scaleY*10) {
line(20, height - i, width, height - i);
text(i / scaleY, 5, height - i);
}
stroke(255);
graph.drawAll(smoothArray, lngth, scaleX, scaleY);
}
void mousePressed() {
if ((scaleX-1 != 0) && (scaleY+1 != 0) && (mouseButton == LEFT)) {
scaleX--;
scaleY++;
redraw();
} else if ((scaleX+1 != 0) && (scaleY-1 != 0) && (mouseButton == RIGHT)) {
scaleY--;
scaleX++;
redraw();
}
}
fileLoad
class fileLoad {
int k = 0;
int s = 0;
int p = 0;
int last_s;
int[][] disassemble2array(String[] lorem) {
//String[] lorem = loadStrings(fileName);
int[][] temp = new int[lorem.length][10];
for (int i = 0; i < lorem.length - 1; i++) {
last_s = 0;
for (s = 0; s < lorem[i].length() - 1; s++) {
if (lorem[i].charAt(s) == ';') {
temp[i][p] = int(lorem[i].substring(last_s, s));
//println(temp[i][p]);
last_s = s + 1;
p++;
}
}
temp[i][p] = int(lorem[i].substring(last_s, s+1));
//println(temp[i][p]);
//println();
s = p = 0;
}
return temp;
}
int[][] smoothen(int[][] arr) {
for (int i = 12; i < arr[i].length - 12; i++) {
for (int col = 1; col < arr[i].length-1; col++) {
arr[i][col] = (arr[i-12][col] + arr[i-11][col] + arr[i-10][col] + arr[i-9][col] + arr[i-8][col] + arr[i-7][col] + arr[i-6][col] + arr[i-5][col] + arr[i-4][col] + arr[i-3][col] + arr[i-2][col] + arr[i-1][col] + arr[i][col] + arr[i+1][col] + arr[i+2][col] + arr[i+3][col] + arr[i+4][col] + arr[i+5][col] + arr[i+6][col] + arr[i+7][col] + arr[i+8][col] + arr[i+9][col] + arr[i+10][col] + arr[i+11][col] + arr[i+12][col])/25;
}
}
return arr;
}
}
errors
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet.selectCallback(PApplet.java:6484)
at processing.core.PApplet.access$0(PApplet.java:6477)
at processing.core.PApplet$3.run(PApplet.java:6389)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.NullPointerException
at test_file_sketch.fileSelected(test_file_sketch.java:53)
... 21 more
Answers
Can you provide your text file?
Do you get the error after you load your file?
Kf
text file is just csv
and yes, file gets loaded and error pops after
Notice three major changes below. The definition of disassemble2arrayBB() was just an extra step but probly not needed.
Kf
thanks kfrajer errors are gone
but now it seems like file does not actually loading
full code down here, it should draw graphs based on data readings from file
int lngth = 10000; int scaleX = 5; int scaleY = 2; String fileName = new String(); String[] lorem = new String[lngth]; int[][] endArray = null; int[][] smoothArray = new int[lngth][10]; drawGraph graph; fileLoad load; void setup() { noLoop(); size(1800, 600); selectInput("Select a file to graph: ", "fileSelected", new File(dataPath(""))); } void fileSelected(File selection) { if (selection == null) { println("Window was closed or the user hit cancel."); exit(); } else { println(selection.getAbsolutePath()); fileName = selection.getAbsolutePath(); println(fileName); } } void draw() { background(0); stroke(50); fill(255); if (fileName.equals("")==false && endArray==null) { //CHANGED: This block will execute only once endArray = new int[lngth][10]; lorem = loadStrings(fileName); println("load succ"); endArray = load.disassemble2array(lorem); smoothArray = load.smoothen(endArray); } for (int i = 0; i < height; i = i+scaleY*10) { line(20, height - i, width, height - i); text(i / scaleY, 5, height - i); } stroke(255); graph.drawAll(smoothArray, lngth, scaleX, scaleY); } void mousePressed() { if ((scaleX-1 != 0) && (scaleY+1 != 0) && (mouseButton == LEFT)) { scaleX--; scaleY++; redraw(); } else if ((scaleX+1 != 0) && (scaleY-1 != 0) && (mouseButton == RIGHT)) { scaleY--; scaleX++; redraw(); } } class fileLoad { int k = 0; int s = 0; int p = 0; int last_s; int[][] disassemble2array(String[] lorem) { //String[] lorem = loadStrings(fileName); int[][] temp = new int[lorem.length][10]; for (int i = 0; i < lorem.length - 1; i++) { last_s = 0; for (s = 0; s < lorem[i].length() - 1; s++) { if (lorem[i].charAt(s) == ';') { temp[i][p] = int(lorem[i].substring(last_s, s)); //println(temp[i][p]); last_s = s + 1; p++; } } temp[i][p] = int(lorem[i].substring(last_s, s+1)); //println(temp[i][p]); //println(); s = p = 0; } return temp; } int[][] smoothen(int[][] arr) { for (int i = 12; i < arr[i].length - 12; i++) { for (int col = 1; col < arr[i].length-1; col++) { arr[i][col] = (arr[i-12][col] + arr[i-11][col] + arr[i-10][col] + arr[i-9][col] + arr[i-8][col] + arr[i-7][col] + arr[i-6][col] + arr[i-5][col] + arr[i-4][col] + arr[i-3][col] + arr[i-2][col] + arr[i-1][col] + arr[i][col] + arr[i+1][col] + arr[i+2][col] + arr[i+3][col] + arr[i+4][col] + arr[i+5][col] + arr[i+6][col] + arr[i+7][col] + arr[i+8][col] + arr[i+9][col] + arr[i+10][col] + arr[i+11][col] + arr[i+12][col])/25; } } return arr; } } class drawGraph { color[] colarray = { color(255,204,0), color(91,100,110), color(185,65,200), color(0,145,35), color(245,35,200), color(108,122,89), color(0,33,55), color(255,79,0), color(202,58,39), color(127,255,212), color(255,0,0) }; void drawAll(int [][] arr, int lngth, int scaleX, int scaleY) { for (int i = 0; i < lngth; i = i+scaleX) { for (int column = 1; column < arr[i].length-1; column++) { stroke(colarray[column]); fill(colarray[column]); ellipse(i/scaleX, height - arr[i][column]*scaleY, 2, 2); } } } }