Ik krijg de volgende error code in mijn browser: Java.lang.StringIndexOutOfBoundsException
Dit is mn code:
Dit is mn code:
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
| import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import java.io.*;
public class ticker extends Applet {
String [] beursaandeel;
String [] beursnotering;
String [] beurspercentage;
String beurs2 = "Hier komen de beurzen enzo";
String beurs = "";
String stream = "";
String stream2 = "";
int x=500;
int x2=500;
beweegTicker ticker;
Image OSC; //Voor de dubbele buffer
int widthOfOSC, heightOfOSC; //Voor de dubbele buffer
Color rood, lichtgrijs, zwart;
Font font;
String URLinhoud="";
static final int maxbeurstemp=15;
int start = -4;
int test;
public void init(){
setBackground(lichtgrijs);
fetchURL2("http://teletekst.nos.nl/cgi-bin/tt/nos/page/t/m/520-1");
beurs = URLinhoud;
stream2 = beurs2;
beursaandeel = new String[maxbeurstemp];
beursnotering = new String[maxbeurstemp];
beurspercentage = new String[maxbeurstemp];
for(int i = 0 ; i < maxbeurstemp ; i++){
beursaandeel[i] = beurs.substring( start + 270 + 44*i , start + 282 + 44*i );
beursnotering[i] = beurs.substring( start + 292 + 44*i , start + 298 + 44*i );
beurspercentage[i] = beurs.substring( start + 301 + 44*i , start + 302 + 44*i );
beurspercentage[i] = (beurspercentage[i] + beurs.substring( start + 303 + 44*i , start + 309 + 44*i ));
stream += (beursaandeel[i] + beursnotering[i] + " " + beurspercentage[i] + " | ");
}
ticker = new beweegTicker(this);
ticker.start();
rood = new Color(186,0,0);
lichtgrijs = new Color(203,203,203);
zwart = new Color(0,0,0);
font = new Font("Courier",0,12);
}
public void paint(Graphics g){
g.setColor(zwart);
g.setFont(font);
g.drawString(stream,x,18);
g.drawString(stream2,x2,40);
g.setColor(rood);
g.drawRect(0,0,497,47);
g.drawRect(1,1,495,45);
g.drawRect(0,23,497,1);
}
public void update(Graphics g) { //de beroemde dubbele buffer
if (OSC == null || widthOfOSC != getSize().width || heightOfOSC != getSize().height) {
OSC = null;
OSC = createImage(getSize().width, getSize().height);
widthOfOSC = getSize().width;
heightOfOSC = getSize().height;
}
Graphics OSG = OSC.getGraphics();
OSG.setColor(getBackground());
OSG.fillRect(0, 0, widthOfOSC, heightOfOSC);
OSG.setColor(getForeground());
OSG.setFont(getFont());
paint(OSG);
g.drawImage(OSC,0,0,this);
}
void fetchURL2(String urlString)
{
try
{
URL url = new URL(urlString);
InputStream content = (InputStream) url.getContent();
BufferedReader in = new BufferedReader(new InputStreamReader(content));
String line;
int i=0;
while ((line = in.readLine()) != null)
{
i++;
if (i==52){
URLinhoud += line;
}
}
}
catch (MalformedURLException e)
{
System.out.println("Invalid URL");
}
catch (IOException e)
{
System.out.println("Error reading URL");
}
}
}
class beweegTicker extends Thread {
Thread beweeg;
ticker applet;
public beweegTicker( ticker applet ){
this.applet = applet;
}
public void run() {
while( true ) {
applet.x-=5;
applet.x2-=8;
applet.repaint();
if(applet.x < (applet.stream.length()*-7)){
applet.x = 500;
}
if(applet.x2 < (applet.stream2.length()*-7)){
applet.x2 = 500;
}
try {
beweeg.sleep(100);
}
catch(InterruptedException e){}
}
}
} |