I have a function which fetches a certain website's HTML code. Eventually that function will return the whole page as an array. I am trying to save the page in another array, but it will always throw an exception (ArrayIndexOutOfBoundsException) for some reason.
I am not sure if I am just missing something elementary or if it's more than just that. To give you some of my code:
protected String[] doInBackground(String... login)
{
String[] page = new String[1024];
try {
page = executeHttpGet(); //THIS IS WHERE IT FAILS
} catch (Exception e) {
page[0] = "Error";
}
return page;
}
public String[] executeHttpGet() throws Exception {
URL u;
InputStream is = null;
DataInputStream dis;
String s;
int i = 0;
String[] page = new String[1024];
addSecurityException();
Authenticator.setDefault(new MyAuthenticator(activity));
try {
u = new URL("https://myurl.com");
is = u.openStream();
dis = new DataInputStream(new BufferedInputStream(is));
while ((s = dis.readLine()) != null) {
if (s.toString().length() > 10)
{
page[i] = s.toString();
i++;
}
}
} catch (IOException ioe) {
}
finally {
try {
is.close();
} catch (IOException ioe) {
}
}
return page;
}
}
Does anyone have any ideas why I am not able to assign the returned array to the array in doInBackground()? Help would be greatly appreciated.
page[1024] = s.toString(), which is a disallowed index of your array.