Hello again. I'm trying to take as an input an ArrayList<Strin g> and utilize String's .spit(delimiter ) method to turn that into a String[][]. I'm getting some kind of error though (I'll post the code and error lower down).
Here's a simple example:
Here's my code (main method and the table implementation method where I'm using the .spit("\\") method):
[code=java]
public static void main(String args[]) {
ArrayList<Strin g> temp = new ArrayList<Strin g>(2);
temp.add("heade rTest\\headerSe ctionTest\\");
temp.add("heade rTest\\start-time\\sameLastP artTest");
temp.add("heade rTest\\end-time\\sameLastP artTest");
temp.add("DataT est\\TimeTest\\ ");
temp.add("DataT est\\PieceOfDat aTest\\");
runTCW rTCW = new runTCW(temp);
rTCW.start();
try {
rTCW.join();
} catch (InterruptedExc eption e) {
e.printStackTra ce();
}
}
[/code]
[code=java]
public MyTableModel(Ar rayList<String> al) {
numRows = al.size();
data = new Object[numRows][numCols];
String[][] tagsSeparated = new String[numRows][];
for (int i = 0; i < numRows; i++) {
tagsSeparated[i] = al.get(i).split ("\\"); //This is where the error is reported, where I use the .split("\\") method
}
for (int i = 0; i < numRows; i++) {
data[i][0] = new Boolean(true);
data[i][1] = al.get(i);
data[i][2] = al.get(i);
Utilities.print (tagsSeparated[i]);
data[i][3] = al.get(i);
}
}
[/code]
And the error it spits out:
I don't completely understand this error. Any and all help is much appreciated.
-blazed
Here's a simple example:
Code:
Input ArrayList would be:
ArrayList<String> temp = new ArrayList<String>(2);
temp.add("headerTest\\headerSectionTest\\");
temp.add("headerTest\\start-time\\sameLastPartTest");
temp.add("headerTest\\end-time\\sameLastPartTest");
temp.add("DataTest\\TimeTest\\");
temp.add("DataTest\\PieceOfDataTest\\");
The String[][] that I want would be (assuming my code works):
String[][] splittedStrings = new splittedStrings[temp.size()][];
splittedStrings[0] = { "headerTest", "headerSectionTest" };
splittedStrings[1] = { "headerTest", "start-time", "sameLastPartTest" };
splittedStrings[2] = { "headerTest", "end-time", "sameLastPartTest" };
splittedStrings[3] = { "DataTest", "TimeTest" };
splittedStrings[4] = { "DataTest", "PieceOfDataTest" };
[code=java]
public static void main(String args[]) {
ArrayList<Strin g> temp = new ArrayList<Strin g>(2);
temp.add("heade rTest\\headerSe ctionTest\\");
temp.add("heade rTest\\start-time\\sameLastP artTest");
temp.add("heade rTest\\end-time\\sameLastP artTest");
temp.add("DataT est\\TimeTest\\ ");
temp.add("DataT est\\PieceOfDat aTest\\");
runTCW rTCW = new runTCW(temp);
rTCW.start();
try {
rTCW.join();
} catch (InterruptedExc eption e) {
e.printStackTra ce();
}
}
[/code]
[code=java]
public MyTableModel(Ar rayList<String> al) {
numRows = al.size();
data = new Object[numRows][numCols];
String[][] tagsSeparated = new String[numRows][];
for (int i = 0; i < numRows; i++) {
tagsSeparated[i] = al.get(i).split ("\\"); //This is where the error is reported, where I use the .split("\\") method
}
for (int i = 0; i < numRows; i++) {
data[i][0] = new Boolean(true);
data[i][1] = al.get(i);
data[i][2] = al.get(i);
Utilities.print (tagsSeparated[i]);
data[i][3] = al.get(i);
}
}
[/code]
And the error it spits out:
Code:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
^
at java.util.regex.Pattern.error(Pattern.java:1700)
at java.util.regex.Pattern.compile(Pattern.java:1453)
at java.util.regex.Pattern.<init>(Pattern.java:1130)
at java.util.regex.Pattern.compile(Pattern.java:822)
at java.lang.String.split(String.java:2293)
at java.lang.String.split(String.java:2335)
at TagChoosingWindow$MyTableModel.<init>(TagChoosingWindow.java:210)
at TagChoosingWindow.<init>(TagChoosingWindow.java:39)
at runTCW.<init>(runTCW.java:14)
at TagChoosingWindow.main(TagChoosingWindow.java:157)
Process completed.
-blazed
Comment