Voor een prototype ben ik begonnen met Arduino en Processing en dit zijn mijn eerste stapjes in deze taal maar nu loop ik tegen een probleem op wat ik met behulp van google ook niet weet op te lossen.
Deze code moet afhankelijk van de code die Arduino doorstuurt een video afspelen. Nu reageert het geheel nogal erg traag maar het werkt 9 van de 10 keer ook niet. Dan krijg ik de volgende error melding.
Het lijkt er dus op of de variabele myMovie leeg is en dat kan ik ook bevestigen als ik println(myMovie); doe voordat die variabele aangeroepen wordt. Dan word er Null geprint. Het vreemde is nogmaals dat hij het soms wel doet en ik dus niet begrijp hoe dit komt want als het goed is word de variabele myMovie public gedeclareerd en gevuld in de functie pageCheck die in de draw functie voor image(myMovie, 0, 0); komt.
Ik snap dat deze code nog niet heel netjes is en ik met meer functies en arrays zou kunnen gaan werken en later ook nog object oriented maar ik wil het eerst graag werkend proberen te krijgen met de handelingen die ik nu begrijp. Zo zijn de verschillende if statements niet heel netjes en al die booleans zouden ook anders kunnen.
Deze code moet afhankelijk van de code die Arduino doorstuurt een video afspelen. Nu reageert het geheel nogal erg traag maar het werkt 9 van de 10 keer ook niet. Dan krijg ik de volgende error melding.
code:
1
2
3
4
5
6
7
| Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PGraphics.image(Unknown Source)
at processing.core.PApplet.image(Unknown Source)
at playing_videos_on_variable.draw(playing_videos_on_variable.java:51)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662) |
Het lijkt er dus op of de variabele myMovie leeg is en dat kan ik ook bevestigen als ik println(myMovie); doe voordat die variabele aangeroepen wordt. Dan word er Null geprint. Het vreemde is nogmaals dat hij het soms wel doet en ik dus niet begrijp hoe dit komt want als het goed is word de variabele myMovie public gedeclareerd en gevuld in de functie pageCheck die in de draw functie voor image(myMovie, 0, 0); komt.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
| /*
* Sketch to start playing the right videofile when a certain sensor value is communicated
*/
import processing.serial.*; //two libraries are added, one for the serial communication and the other one to play the movie files.
import processing.video.*;
Movie myMovie;
Serial port;
int pageValue; //This variable is later used to store the data input from the arduino
void setup() {
size(800, 480, P3D);//800x480 is the resolution of the video files, this is allready pretty sluggish and the intention was to play it on a 4" screen therefore the resolution is not higher.
noStroke(); //P3D is added to the setup so the videofile starts playing actually, otherwise processing will just crash.
port = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
if (0 < port.available()) { //Check to see if there is actually data for me available
pageValue = port.read(); // Here I store the information from the datacommunication in the variable pageValue
pageCheck(); //Here the function pageCheck is called which starts to play videofiles determined on which page you are.
}
background(204);
println(pageValue); //Check to see what values the variable pageValue holds, another check to see how the communication is going and where an error occurs.
println(myMovie);
image(myMovie, 0, 0);
}
void movieEvent(Movie myMovie) {
myMovie.read();
}
boolean played1 = false;
boolean played2 = false;
boolean played3 = false;
boolean played4 = false;
boolean played5 = false;
boolean played6 = false;
boolean played7 = false;
boolean played8 = false;
void pageCheck() { //This function checks which value the variable pageValue is and then selects the right videofile for that and then starts playing that file. I could have done this in an array but because of all the troubles I did not manage to make this in time.
if (pageValue == 1 && played1 == false) {
played1 = true;
myMovie = new Movie(this, "pagina 5.mp4");
myMovie.play();
image(myMovie, 0, 0);
}
if (pageValue == 2 && played2 == false) {
played2 = true;
myMovie = new Movie(this, "pagina 7.mp4");
myMovie.play();
image(myMovie, 0, 0);
}
if (pageValue == 3 && played3 == false) {
played3 = true;
myMovie = new Movie(this, "pagina 9.mp4");
myMovie.play();
image(myMovie, 0, 0);
}
if (pageValue == 4 && played4 == false) {
played4 = true;
myMovie = new Movie(this, "pagina 11.mp4");
myMovie.play();
image(myMovie, 0, 0);
}
if (pageValue == 5 && played5 == false) {
played5 = true;
myMovie = new Movie(this, "pagina 13.mp4");
myMovie.play();
image(myMovie, 0, 0);
}
if (pageValue == 6 && played6 == false) {
played6 = true;
myMovie = new Movie(this, "pagina 15.mp4");
myMovie.play();
image(myMovie, 0, 0);
}
if (pageValue == 7 && played7 == false) {
played7 = true;
myMovie = new Movie(this, "pagina 17.mp4");
myMovie.play();
image(myMovie, 0, 0);
}
if (pageValue == 8 && played8 == false) {
played8 = true;
myMovie = new Movie(this, "pagina 19.mp4");
myMovie.play();
image(myMovie, 0, 0);
}
} |
Ik snap dat deze code nog niet heel netjes is en ik met meer functies en arrays zou kunnen gaan werken en later ook nog object oriented maar ik wil het eerst graag werkend proberen te krijgen met de handelingen die ik nu begrijp. Zo zijn de verschillende if statements niet heel netjes en al die booleans zouden ook anders kunnen.