writer in java getting stuck with 1 value

Questions about programming languages and debugging
Post Reply
User avatar
l0ngb1t
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 598
Joined: 15 Apr 2009, 16:00
15
Contact:

writer in java getting stuck with 1 value

Post by l0ngb1t »

hey am writing a code that simply create an html table from a given .txt file
for example if the txt file containe
badbrain,founder
cats,admin
ph0,admin
me,member

:P nthg personnal just an example
the program will create the necessary html code for the table
like :
<table ... >
<tr>
<td>badbrain</td>
etc ...

but the thing is that when it comes to writing it stuck with the first value i gave to it
when it goes in loop

this is code
the problem accure when it comes to writing the file, starting from line 70 till 78

and i add a litle print thingy in line 71 to make sure that am not doing a logical mistake
and i guess am not
the print should work for any table that have 2 lines and 2 values per line

so it;s all about the writing thing :(:(:(:(:(

helppppppppppppp
P.S the quote and the url tag is way muich better :D
There is an UNEQUAL amount of good and bad in most things, the trick is to work out the ratio and act accordingly. "The Jester"

User avatar
John_W
forum buddy
forum buddy
Posts: 24
Joined: 02 May 2010, 16:00
13
Contact:

Re: writer in java getting stuck with 1 value

Post by John_W »

The problem arises when there's an empty line, i beautified your code and changed it a bit: http://code.suck-o.com/42324" onclick="window.open(this.href);return false;

User avatar
l0ngb1t
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 598
Joined: 15 Apr 2009, 16:00
15
Contact:

Re: writer in java getting stuck with 1 value

Post by l0ngb1t »

thak you jhon for the fix =D> :D and thanks for the plastic surgery :P
can you explain what was exactly hapening and how you fix it ?
There is an UNEQUAL amount of good and bad in most things, the trick is to work out the ratio and act accordingly. "The Jester"

User avatar
John_W
forum buddy
forum buddy
Posts: 24
Joined: 02 May 2010, 16:00
13
Contact:

Re: writer in java getting stuck with 1 value

Post by John_W »

The problem was an ArrayIndexOutOfBoundsException caused by a too small array; your code assumed that the array would always contain 4 Strings and crashed if there were less.
You can also omit empty lines by checking the size of the returned array: if (code.length >= 4) for ...
That is also a reason why I prefer "for (Object i : ListOrArray)"-loops instead of traditional "for (int i ; ... ; ++i)"-loops.

Post Reply