.I have a Map called list yes I know horrible naming but I'm just doing it while I'm learning wouldn't do so in a proper application,anyway the Map consists of an Integer and a Print object there is three print objects,I structured the dat file to first contain the size of the map,then I wrote the start location of the actual print data and I gave enough space to come back and place the indexes in them before the print data,anyway the code was working fine when I first tested it,it seems to retrieve the correct ID(num) but when I try to print out the number value at the start of the print data it gives me a huge number -419430400 when the number -419430400 but what it should print is 1,2,3 after than it seems to go to the end of the file,I expected this to run three times,
if anybody could look through my code and tell me why this is occurring I would be more than greatful,sorry the code is quite long I couldn't pinpoint where the exact bug is,
to the main method that created the dat file and recompiled it,seemed to fix the problem but there is still a MAJOR bug,
for some reason when I loop through the index map it only prints the last two indexes and not the first
also I deleted the code that made the list I maybe should have just commented it out I made it to a txt file with a FileWriter then here is the code I used to read it in
then I wrote the info to a dat file
as I said for some reason it won't print the first index or add it to the map which I named list
- X 2
It is not possible to test with the small random bits of code posted on this thread.
Chrome Eclipse IDE Java Postgres Database VI Editor
Adam: you have a habit of posting incomplete code. Read about what a SSCCE is (that should be a link). Here's what one would look like in your case:
anyway here is what I wrote
write this code to create a txt file or just create it in a text editor
then read the data into the file and compile it so the variables are intialised
compile again then uncomment or delete the code that created the dat file then add this code but don't compile until all of it is added
that should be the final code
finally create two classes one for index and one for print
sorry about all the code there is quite a lot,but I really appreciate your effort means a lot to me =)
I'm just baffled why it skips the first entry in the index
Adam Chalkley wrote:Hi Carey,thanks for the advice the only reason I used the static blocks was so I could read and initialise the variables before the main method ran
Why? I doesn't appear to be necessary to me. How are you going to test it without separate read and write methods?
Also, keep it simple until you get it working. The way you are reading and writing the txt file is wrong. Forget the txt file for now and hard code the initialization.
Add some lines of code to that class to read in the contents of the hi.txt file and print it. Work on that until what is read and printed is the same as what was written.
The rest of the code that was posted is just in the way of working on and solving the problem.
If anyone wants to look at the final product and compare it to the code that skipped the first value that would be more than great because I'm still puzzled to why the first value got skipped
ignore the comments they are there just to show you how I created the file and read from the file
anyway it's not short Knute haha but it's just the solution
PS Carey I am now going to rewrite the code without the static block =) thanks for the advice means a lot