• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Formating formated string back into original number

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

213.999.222

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!
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jerne Pozen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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\PartsBuilder.java:935: 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
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
crispy bacon. crispy tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic