• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Highscore not working

 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im trying to set up a highscore list for my game. But for some reason cant get it to work. If anyone can help that would be awesome.



Sorry if this is an inconvience to anyone.
 
AnujS Sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you unable to set the "HighScore"??

Are you getting a compiler error or is it not working as expected??

If it is the first one, then please post the error for us to help you. If it is the latter one, for what all inputs are you not getting the expected output.

My advice would be to identify such inputs and debug through your code until you find the root cause of the problem. Change the code appropriately and test again.

 
Ove Lindström
Ranch Hand
Posts: 326
Android Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need to store the highscore list in a readable text form or just as persistence between runs?

If the first, then you are on the right track. If the second, why not just serialize the whole array/list to a file and read it when you start the program?
 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ove Lindström wrote:Do you need to store the highscore list in a readable text form or just as persistence between runs?

If the first, then you are on the right track. If the second, why not just serialize the whole array/list to a file and read it when you start the program?


To answer your question i put everything i know in the other reply
 
Paul Clapham
Sheriff
Pie
Posts: 20978
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What other reply?
 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AnujS Sharma wrote:Why are you unable to set the "HighScore"??

Are you getting a compiler error or is it not working as expected??

If it is the first one, then please post the error for us to help you. If it is the latter one, for what all inputs are you not getting the expected output.

My advice would be to identify such inputs and debug through your code until you find the root cause of the problem. Change the code appropriately and test again.



I bieleve it is the first. Here is the error
Exception in thread "main" java.io.FileNotFoundException: Highscorelist.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at testthing.main(testthing.java:463)

By the way Im as dumb as a boxx of roxx so im sorry if I sound stupid.
 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:What other reply?

LOL sorry didnt think you would get it so quickly
 
AnujS Sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The exception thrown says that it cannot find the file.

When you're specifying the file, specify the absolute path. Maybe the the file that you want to read & write is not in the same directory or sub directory as that of the your java class file. This is why it is throwing an exception. Try specifying the whole path like, "D:\FolderName\HighScore.txt".


 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AnujS Sharma wrote:The exception thrown says that it cannot find the file.

When you're specifying the file, specify the absolute path. Maybe the the file that you want to read & write is not in the same directory or sub directory as that of the your java class file. This is why it is throwing an exception. Try specifying the whole path like, "D:\FolderName\HighScore.txt".




1. sorry for the late reply

2. sorry im about to sound stupid.

So you want me to replace the (new FileReader("Highscorelist.txt")); with something like (new FileReader("D:\Downloads\Highscore.txt")); ?

 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't apologize for asking questions...there is a LOT to learn, and we all have to start somewhere.

Assuming your file is in the D:\Downloads directory, and assuming it really is named "Highscore.txt", then yes...almost.

remember that in String literals in java, a backslash character '\' has special meaning. so if you do it exactly as you wrote, java will think the "\D" and "\H" are 'special characters', and will most likely complain. you need to tell it you want a LITERAL backslash, and the way you do that is to use TWO in a row:

(new FileReader("D:\\Downloads\\Highscore.txt"));

at least...i think. I haven't tested this...but this is the basic idea.

Note that it will also vary depending on what OS you are using...windows is different from Linux is different from MacOS. Somone (probably Campbell) will most likely chime in soon and tell you the RIGHT way to do it with directory separators, but this should work for now.
 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:don't apologize for asking questions...there is a LOT to learn, and we all have to start somewhere.

Assuming your file is in the D:\Downloads directory, and assuming it really is named "Highscore.txt", then yes...almost.

remember that in String literals in java, a backslash character '\' has special meaning. so if you do it exactly as you wrote, java will think the "\D" and "\H" are 'special characters', and will most likely complain. you need to tell it you want a LITERAL backslash, and the way you do that is to use TWO in a row:

(new FileReader("D:\\Downloads\\Highscore.txt"));

at least...i think. I haven't tested this...but this is the basic idea.

Note that it will also vary depending on what OS you are using...windows is different from Linux is different from MacOS. Somone (probably Campbell) will most likely chime in soon and tell you the RIGHT way to do it with directory separators, but this should work for now.


Thanks alot for the help but it still not getting the .txt I double checked and tripled checked all of the spelling a captializations. It now reads

I know i must be doing something wrong. Also i use windows if it helps at all. I also am not sure but i use eclipse.
 
AnujS Sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you change it for the FileReader as well??

Try debugging the program. Use System.out.println() to see till where the program is executing and at what line precisely you are getting the error.


I can see that you haven't pasted the full code, may be that's why we are unable to help you..
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also, and this is a WAG...does the file actually exist?

based on the code in your original post, the first thing you try and do is open it with the reader. I'm not sure what that does if the file isn't already there, but a "Filenotfound" exception sounds like a reasonable thing to happen.

if it is not, try putting a file there, even if it is empty.
 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:also, and this is a WAG...does the file actually exist?

based on the code in your original post, the first thing you try and do is open it with the reader. I'm not sure what that does if the file isn't already there, but a "Filenotfound" exception sounds like a reasonable thing to happen.

if it is not, try putting a file there, even if it is empty.


I actually didnt have it in the original post but after ward when i changed the code I made the .txt and placed it in the everything folder. So yeah thanks for the help though
 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AnujS Sharma wrote:Did you change it for the FileReader as well??

Try debugging the program. Use System.out.println() to see till where the program is executing and at what line precisely you are getting the error.


I can see that you haven't pasted the full code, may be that's why we are unable to help you..


I didnt think the rest of the code could affect it because the only part of the code that will lead to the highscore is when my while loop ends. But if you think so i could post the rest.

Edit: I did it to the writer and the reader.....
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12100
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this...

Write a brand new program, something like "FileReadTest.java". Have it do nothing but open the file, read and print each line, then close the file.

See if you can get that to work. If not, post THAT code here, since it should only be about 20-30 lines, max.

If it DOES work, then look at what may be different between your new test program and your existing one. Running from the same directory? File name the same? etc.
 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:Try this...

Write a brand new program, something like "FileReadTest.java". Have it do nothing but open the file, read and print each line, then close the file.

See if you can get that to work. If not, post THAT code here, since it should only be about 20-30 lines, max.

If it DOES work, then look at what may be different between your new test program and your existing one. Running from the same directory? File name the same? etc.


Thanks for your help but my comp is going crazy ill edit this responce as soon as i can get my computer stable again.
 
Kacey Simeon
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not getting back to ya guys sooner i completely forgot to tell you guys. I fixed the problem. Thanks for everyones help! You guys are such an awesome community
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic