File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Formating formated string back into original number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Formating formated string back into original number" Watch "Formating formated string back into original number" New topic

Formating formated string back into original number

Jerne Pozen

Joined: Apr 19, 2011
Posts: 4
Right I'm doing a simple application in Netbeans, that deals with large numbers so I want my Text Fields to be Formated.
Now right after input of the number to it(when you press enter, or when text field losses focus) I made it that a number is formated. like this number: 213999222 into:


I made it with this code:

now I want it that when a text field gets focus, I turn the formated string back into the old number: 213999222.
So that it would be like in excel (when you have a cell formated, and you double click on it to edit the data, its turned back into pure numbers)

I tried this code:

but I get a RuntimeException: Uncompilable source code
thanks for help!
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Hi and welcome to the JavaRanch.

Try to clean your project and recompile your sources. If you get a question about wanting to run your program even if it doesn't compile press no.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Jerne Pozen

Joined: Apr 19, 2011
Posts: 4
did a clean build, still the same error
Just did a completely new project with just that Textfield and the codes I inlucded above. Still the same error, I guess it can't be done that way.
Matthew Brown

Joined: Apr 06, 2010
Posts: 4543

Sounds like your IDE is messing with you, somehow. Because if the source isn't compilable, you should get an error when you compile it - and this error will tell you what the problem is. The error you've described is because your IDE is trying to run the code anyway.

You might be able to play with the NetBeans settings to get it to behave. What definitely should work, though, if that fails is to compile from the command line using javac.
Jerne Pozen

Joined: Apr 19, 2011
Posts: 4
I do get an error when I build it:

Compiling 1 source file to C:\Users\Uporabnik\Documents\NetBeansProjects\PartBuilder\build\classes
C:\Users\Uporabnik\Documents\NetBeansProjects\PartBuilder\src\Mojster\ unreported exception java.text.ParseException; must be caught or declared to be thrown
Number dekodiranje=nf.parse(pFul.getText());
1 error
C:\Users\Uporabnik\Documents\NetBeansProjects\PartBuilder\nbproject\build-impl.xml:531: The following error occurred while executing this line:
C:\Users\Uporabnik\Documents\NetBeansProjects\PartBuilder\nbproject\build-impl.xml:261: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

also when I first put the code in, it didn't show any error on the source code, then it suddenly poped up after I ran it
now it shows it in source code too
Jerne Pozen

Joined: Apr 19, 2011
Posts: 4
Oh I found the solution, it looks that all it needs is a Try-Catch statement
and works ok now.
So the final code that works:

Thank for help guys and thank you for the welcome on this Forum Wouter Oet!
I agree. Here's the link:
subject: Formating formated string back into original number
It's not a secret anymore!