Michael Comerford

Greenhorn
+ Follow
since Jan 16, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Michael Comerford

Thanks Dennis, you're totally right. Once I sat down and actually went through the process I was attempting to automate step by step and wrote out dummy datasets etc. it made much more sense and I have now redesigned my code and it is now working for my purposes.

11 years ago
Hello, thanks for taking a look at my problem.

I'm implementing a merge sort algorithm in my code in order to sort data which is currently held in an arraylist of arraylists. The splits seem to be functioning fine (i've been doing a lot of System.out.print at every stage to make sure its doing what I think it's doing) However, when I get into the merge code I don't seem to be able to get it to run. I get stuck in an infinite loop and when I print what's going on to the console I get 0 over and over again from the output at line No. 15 in Merge.java

Can anyone see any rookie errors? I've tried playing with how the loops are nested in case I missed a curly bracket in the right place.

Thanks :-)

Michael

So below are my two simple classes to implement the merge sort



and the second one....

11 years ago
Got it nailed thanks for your help guys!
12 years ago
No problem is here is the StataColumn class


12 years ago
Hi Rob, sure, here is the code I inserted before line 47 in the original.

12 years ago
Hi guys, thanks for the help narrowing this down

the console returns the folllowing when I included the System.out.prinf code

This object table is not null: true
This object table.get(i) is not null: true
This object tokens not null: true
This objects tokens[i] not null: trueException in thread "main" java.lang.NullPointerException
at StataColumn.add(StataColumn.java:32)
at CsvIn.main(CsvIn.java:61)

So tokens[i] is null?
tokens is a String array that takes it input from a Scanner that scans the csv file and splits it into elements and stores it in tokens[], so is it saying the i'th element is null?
Or am I missing something?

12 years ago
Hi guys, this problem has been frustrating me for hours, I've tried changing the code with little tweaks and commenting out bits to test it and dumping stuff to system.out to see what is happening along the way but I can't find a reason for this exception.

I'm building a csv parser (yes I know some already exist but my supervisor wants me to do this as part of a project) My code is included below

the test csv file I use looks like this:

"CaseId","Age","Name","Height [m]"
1,21,"Alan",1.82
2,45,"Steve",1.53
3,54,"Rick",1.72
4,32,"Jon",1.49
5,67,Chris,1.93

The exception occurs at line 47
all I'm doing in that section is differentiating between types, so storing the type of each column of data as either "s" for a string, "r" for a double, and "i" for an integer and then adding it to my 'table'(which is an arraylist of arraylists).

Any help greatly appreciated!

12 years ago
Wim thanks that was a really useful explanation, I fixed the problem and the code works now.

Michael
12 years ago
thanks for your help guys, I'm now trying to format my output so that it is in columns rather than rows.

The following code gives an IndexOutOfBoundsException at line 100 after printing the format I want for the first entry

I've had a look through the documentation for this exception and don't see how to resolve it, any clues?

12 years ago
Hi Hunter,

sorry I described the one using PrintWriter in my post and then posted the System.out one! here it is:

this just generates a blank file


12 years ago
Hi there,

Still pretty new at this but I've created an arraylist of arraylists as a 2d data structure for demographic data.

What I'm ultimately trying to do is write the data as csv

In the code below I can output the data to with System.out and it looks right in the console - it prints:

1,2,3,4,5,
21,45,54,32,67,
Alan,Steve,Rick,Jon,Chris,
1.82,1.53,1.72,1.49,1.93,

I thought I could just use the PrintWriter q I've created and use q.print( j.next() + ",") instead of the System.out line, when I try to run it I get a NoSuchElementException.

Any pointers?


12 years ago
Doh! Silly mistake, thanks Matthew!

12 years ago
Hi there,

I'm trying to create an arraylist of arraylists as a data structure to represent demographic data.

I've hit a brick wall already, when I try to add integers to one of my arraylists I get errors.

I'm using Eclipse and this program is for JavaSE 1.6

here's the code...

Eclipse tells me that there is:
Multiple markers at this line
- Syntax error on token(s), misplaced construct(s)
- Syntax error on token "id1", VariableDeclaratorId expected after this
token

at the lines that start caseid.add

Any help greatly appreciated!

Michael

12 years ago