P White

Greenhorn
+ Follow
since Dec 28, 2011
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by P White

Guys,

Thanks for all your help.

I have taken all advice on board and changed the variables to lower case.

I took a break from this and went to the pub last night where I had a thought. What if I put in an extra step?
My thoughts were that I was not sure how the underlying Java system was handling adding the extra linefeeds then shuffling during one operation. Were the extra line feeds a problem?

So I changed the code to:



I initially got an error reading the array as ot counted to 130 and then errored so I put a -1 on the count to stop this. My file has only 128 lines.
This seems to have cured the problem.

I thought you might like to know the solution.
12 years ago
Paul,

Thank you your comments make sense.

I will in future use lower case names for variables.
12 years ago
Paul,

Thank you for your patience.
I have moved the code as you suggest to make it readable I hadn't realised you needed to put it inside the bracket.

Looking at my code I see your point. I am new to this and have trouble passing vaiables between classes (sometimes it seems to work and sometimes it doesn't) hense you will find hard coded bits referring to variables in an another class. This is what happened here the fliename was not passed so I hard coded it as a work around.

I am trying to learn java by creating working apps this is my third.

The code is not pretty I know but until I have spent more time writing bits and peices I will never get to the bottom of my errors and find the solutions to them.

And of course a thank you to everyone else who has taken the time to try to help.
12 years ago
This is the entire code from my csv file reader

I have been experimenting and there are some reduntant lines of code i.e. boolean ready = false:
FYI I was trying to use wait() to allow the shuffle to complete but this concept is completely beyond me................

If I enable the index counter just above I get a seemingly random count and then the error at ColQ.add(temp.get(0));
This is always the line indicated.

Please bear in mind I only get an error when I enable the line "Collections.shuffle(data);

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at quiz.ReadEncryptedFile.ReadCSVFile(ReadEncryptedFile.java:115)
at quiz.UserInterface.main(UserInterface.java:194)

Line 3 should only allow the file to be read if it exists and can be read - this bit (I think) is not causing me a problem, even if it not the way to check.
I have disabled it anyway and tried agian but am still getting the same error.

Thank you all very much.

12 years ago
Matthew,

Thank you for the time you have taken to look at this for me.

If I add a a counter and a line to printout the information contained in "data" like this there are 128 lines of data.

Also if I add a line to print "data" following reader.close() I can see all the data up to and including the last line from my file.

12 years ago
John,

Thank you for this information. It will come in very useful for next time.

I very much appreciate your time in helping me.

Thank you

Paul
12 years ago
Hi,

I have almost finished a program to create and take quizes.

The quiz creator is finished but I have problem with the quiz taker.

The quiz file is a basic .csv file

To stop the student from reading the .csv file I am encrypting the file.

1. I am reading the csv file replacing \r\n with a a ¬, replacing \n with ~, and then replacing the ¬ with \r\n
2. I am then encrypting the file.

When the quiz runs I am decypting the file, replacing the ~ with \n and returning the data to csv format.

The questions and answers display correctly but I want to shuffle the questions

As soon as I add the collections.shuffle into the code I get this error

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at quiz.ReadEncryptedFile.ReadCSVFile(ReadEncryptedFile.java:110)
at quiz.UserInterface.main(UserInterface.java:194)

I think this is caused because the collections.shuffle has not completed.
I have tried to make the program pause but this just delays the error from appearing.

My csv file reader contains this code which is where the problem lies.


12 years ago
I have found a work around to this now.

I am reading the quiz file and replacing the \r\n with a seldom used character and the \n with another seldom used character saving this file to disk then encrypting.

after decryption I am replacing the characters with \r\n and \n respectively.

Perhaps not the best solution but it is working.
12 years ago
and this is the decryptor so that you get your csv file back.

12 years ago
Hi,

Can someone please point me in the right direction. I have been at this all day and am no closer to a solution than I was first thing this morning.

I have written a simple quiz program that reads its information form a csv file. I would like to encrpt the data as the csv file indicates which asnwer is correct.

When I encrypt and decrypt the csv file I am losing any line feeds in the file which messes up the formating of the text in my text areas.

I don't know why perhaps someone would point me in the right direction.

File encryptor:


12 years ago