You are not logged in.

  • Login

1

Monday, October 15th 2007, 4:02pm

Fehler beim Umwandeln von String in einen Double-Wert

Hi,

ich habe mit Eclipse eine kleine Anwendung erstellt, ganz einfach. 2 Textfelder, in denen man Zahlen eingibt. Auf Button.Klick wird etwas berechnet und in dem 3. Textfeld angezeigt.

Leider bekomme ich eine Fehlermeldung, wenn ich versuche die Strings der Textfelder in Double-Werte zu konvertieren. Vielleicht könnt ihr mir ja helfen.

Danke im Voraus.

Java Quellcode

1
2
3
4
5
private void berechne(){ 
	double taktzahl = Double.parseDouble(jLabel_taktzahl.getText());  // Zeile 129 
	double taktzyklus = Double.parseDouble(jLabel_taktzyklus.getText());  
	jTextField_result.setText(Double.toString(taktzahl/taktzyklus));
}



Fehlermeldung:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "Taktzahl"
	at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
	at java.lang.Double.parseDouble(Unknown Source)
	at frame.berechne(frame.java:129)
	at frame.access$0(frame.java:128)
	at frame$1.actionPerformed(frame.java:108)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

This post has been edited 1 times, last edit by "mad" (Oct 15th 2007, 5:07pm)


2

Monday, October 15th 2007, 4:48pm

Der Fehler sagt es doch schon: Der Wert den du in einen double konvertieren möchtest lautet "Taktzahl". Kann es sein, dass das in dem Label drinsteht?

3

Monday, October 15th 2007, 5:07pm

Ach, ich idiot, danke, ich lese das Label anstatt des Textfeldes aus.

Problem hat sich also erledigt.

Danke dir!

Similar threads

Social bookmarks