I have been having a little trouble getting my program to output the results I am wanting.
At first I was having trouble with a cast exception at this line:
out = (ParseResult[]) ipHostsFound.toArray();
The cast exception was:
[Ljava.lang.Object; cannot be cast to [Lfilelocation.struct.ParseResult;
So I ended up changing it to this:
out = (ParseResult[])ipHostsFound.toArray(new ParseResult[ipHostsFound.size()]);
However, I don't want the size of it, i just changed it to that to see if I could get it to work correctly with the output as I was briefly reading some information here:
Here is the source (if you need the ParseResult source I can post it also):
import filelocation.struct.ParseResult;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
/**
*
* @author ******
* Scans the network for computers connected
*/
public class AngryIPParser {
private String ip = "xx.xx.xx.xx";
private String hostname = "host";
private String ping = "m/s";
public ParseResult[] parseResult(BufferedReader reader) throws FileNotFoundException, IOException {
ParseResult[] out;
ArrayList<ParseResult> ipHostsFound = new ArrayList();
try {
boolean bHeadersDone = false;
while (reader.ready()) {
String beanInfo = reader.readLine();
if (!bHeadersDone) {
if (beanInfo.contains("Ping")) {
bHeadersDone = true;
}
}
else {
String[] values = beanInfo.split("," , 3);
ip = values[0];
hostname = values[1];
ping = values[2];
}
}
} catch (Exception e) {
e.printStackTrace();
}
out = (ParseResult[])ipHostsFound.toArray(new ParseResult[ipHostsFound.size()]);
// compiles without errors/exceptions but doesn't function as it should
// out = (ParseResult[]) ipHostsFound.toArray(); <-- comes up with cast exception
System.out.println(out);
return out;
}
/**
*
* @return hostname of the parsed machine
*/
public String getHostname() {
return hostname;
}
/**
*
* @return ipaddress of the parsed machine
*/
public String getIP() {
return ip;
}
}
Anyways I put a print statement in there to see what the results were for my out and it comes up with this:
[Ledu.utexas.arlut.cristal.struct.ParseResult;@5740bb
Overall what I am trying to do is get it to add it to my arrayList ipHostsFound and then create a viewobject out of it, which will later be displayed from my main program.
Could someone point me in the correct direction :)