Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Java reading file problem only occurs on some PC's  (Read 1230 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2013-03-13 05:03:36 »

Hey,
For the last year and a half or so I've been working on a Soldat clone, called Storm2D. (http://storm2d.net)
Having released an alpha version of the game, on my latest video (http://www.youtube.com/watch?v=0Eb-4QJHHeQ) two people have posted that the game crashes at a specific point, both using Windows 7 (same as me). Annoyingly, the problem doesn't happen on my computer, nor 3+ other computers I tested the program on, so it is hard to debug. One of the users helpfully posted the crash log (exception stack trace) and it leads me to believe (although I could be wrong, as the location of the crash is not where the actual problem is) that my problem has something to do with the way I am reading files with the Java scanner.

Note: I bundle the jre with my application so it isn't a problem with different versions of java.

when reading through one of my (biped) files needed for the game, at the start of the line I check if the first 'token' in the line is a number. If it is a number, it means I need to read an extra two parameters at the start. I read the line a slightly different way (because the line contains different parameters). For some reason I think the first token is not being recognized as a number on their machines which means that the first two tokens aren't handled and the whole line is read wrongly.

The code I use to check if the token is a number(note: any type of number, float,double, int etc) is below. Does this handle all cases? (apart from long, huge numbers won't occur)

1  
2  
3  
4  
5  
6  
if (scan.hasNextFloat() || scan.hasNextInt())
{
    ... //process the first two tokens
}

//continue to read the rest of the line.


Alternatively I could use the below code and just use scanner.next() rather than using the other methods(hasNextFloat, etc), but I won't know if it works until one of the users that had the problem in the first place try it again.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public static boolean isNumeric(String str)  
{  
  try  
  {  
    double d = Double.parseDouble(str);  
  }  
  catch(NumberFormatException nfe)  
  {  
    return false;  
  }  
  return true;  
}


Thanks,
Roland


Offline 65K
« Reply #1 - Posted 2013-03-13 06:24:05 »

Try to specify the locale of the scanner to match the number format of the read files.

Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2013-03-13 08:24:27 »

Game looks ace btw. Soldat's one of my favourite games of all time.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roland
« Reply #3 - Posted 2013-03-13 10:58:39 »

Try to specify the locale of the scanner to match the number format of the read files.

Omg! thanks!  Smiley
That was the problem.
I didn't even know about locales Smiley you learn something new every day.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Scanner scan = new Scanner("0.0");
     
System.out.println("Locale: US");
scan.useLocale(Locale.US);
System.out.println("Has next float: " + scan.hasNextFloat());
System.out.println("Has next double: " + scan.hasNextDouble());

System.out.println("Locale: France");
scan.useLocale(Locale.FRANCE); //also GERMAN, ITALIAN, etc.
System.out.println("Has next float: " + scan.hasNextFloat());
System.out.println("Has next double: " + scan.hasNextDouble());


Output:
1  
2  
3  
4  
5  
6  
Locale: US
Has next float: true
Has next double: true
Locale: France
Has next float: false
Has next double: false



Now I just need to remember to never create a Scanner without setting the locale(I made a utility function, but creating Scanners is such a habit  Grin)
Offline roland
« Reply #4 - Posted 2013-03-13 11:03:29 »

Game looks ace btw. Soldat's one of my favourite games of all time.

Cas Smiley

Thanks man!  Smiley
Same. I wish I could go back to the old Soldat days! I played that game almost every day for nearly 5 years. This is one of the reasons why I am making a Soldat clone. People have left the game but nothing has replaced it.

There's still a heap of bugs and things I need to do and features to add, but if I can get some good artwork, etc I think this game could be a hit. Just need to keep at it!
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2013-03-13 11:26:05 »

I think King Arthur's Gold has taken over.

Cas Smiley

Offline roland
« Reply #6 - Posted 2013-03-13 14:13:35 »

I think King Arthur's Gold has taken over.

Cas Smiley

KAG is a good game, but completely different to Soldat IMO. Nothing beats a good game of Soldat  Grin
Offline UprightPath
« Reply #7 - Posted 2013-03-13 14:17:12 »

You might also look at Cortex Command. It seems to have some of the same things in it. But I've never played Soldat and am just basing things on the video of the game you posted. >.> I have played KAG though, and they're somewhat similar.

Offline roland
« Reply #8 - Posted 2013-03-13 14:21:13 »

You might also look at Cortex Command. It seems to have some of the same things in it. But I've never played Soldat and am just basing things on the video of the game you posted. >.> I have played KAG though, and they're somewhat similar.
Yeah Cortex command is a great game too Smiley
I played that a lot for a while. I haven't played online with it though, just with some friends on a single PC.
Offline CyanPrime
« Reply #9 - Posted 2013-03-13 19:32:12 »

Just from reading the title I got the idea that it might be the PC's partition format.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roland
« Reply #10 - Posted 2013-03-13 23:30:05 »

Just from reading the title I got the idea that it might be the PC's partition format.
Ah yeah, sorry the topic title wasn't very clear  XD
But the problem is solved now Smiley
Thanks
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (8 views)
2014-09-21 01:30:30

BurntPizza (9 views)
2014-09-21 00:34:41

moogie (10 views)
2014-09-21 00:26:15

UprightPath (23 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!