Array[0] causes NullPointerException
in
Core Library Questions
•
2 years ago
Hi group,
I have a script that has many problems: The first one is:
The next problem is the clientEvent is being called all the time. It is only to be called when there is data from the Server.
Here is the script:
William Estrada
Mt Umunhum, CA, USA
HTTP://64.124.13.3 ( Mt-Umunhum-Wireless.net )
Skype: MrUmunhum
I have a script that has many problems: The first one is:
This is caused by this line "Old[0] = 0;".Exception in thread "Animation Thread" java.lang.NullPointerException
at I2C_Plot.setup(I2C_Plot.java:33)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:636)
The next problem is the clientEvent is being called all the time. It is only to be called when there is data from the Server.
Here is the script:
import processing.net.*;Any ideas? Thanks for your time.
Client C;
String data;
int X = 1;
int[] Old;
int[] Now;
void setup() {
size(600,200); smooth(); background( 0 );
C = new Client( this, "127.0.0.1", 5204 );
Old[0] = 0;
}
void draw() { }
void clientEvent( Client C ) {
println("Event"); int Yes;
while( ( Yes = C.available() ) > 0 ) {
println("read: " + Yes);
data = C.readStringUntil( '\n' );
print(data);
Now = int( splitTokens( data, " \n" ) );
println(data);
if( Now[0] != Old[0] ) { line( X, 10, X, 20 ); }
point( X, 10 + ( Now[0] * 10 ) );
Old[0] = Now[0];
if( ++X > 600 ) X = 1;
}
}
William Estrada
Mt Umunhum, CA, USA
HTTP://64.124.13.3 ( Mt-Umunhum-Wireless.net )
Skype: MrUmunhum
1