Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

??? getText() Problem

Empfohlene Antworten

Veröffentlicht

weiß einfach nicht so recht weiter, bekomme immer beim konvertrieren eine "NullPointerEception"

hier mal mein BSp. Programm nicht sehr sinnig aber ihr seht denke ich die Stelle die ich meine (actionPreformed)import


java.awt.*;
import java.awt.event.*;

public class Test extends Frame implements ActionListener
{
Button Berechnen, Beenden;
String Wert1, Wert2, Wert3;
TextField TF1, TF2, TF3;

public Test()
{
super("Test1");
addWindowListener(new CloseableFrame());
setLayout(new GridLayout(4, 2));

// Label
Label Lab1 = new Label("1. Eingabe", Label.RIGHT);
Label Lab2 = new Label("2. Eingabe", Label.RIGHT);
Label Lab3 = new Label("Ausgabe", Label.RIGHT);

// Text Felder
TextField TF1 = new TextField("");
TF1.addActionListener(this);
TF1.setName("TF1");
TextField TF2 = new TextField("");
TF2.addActionListener(this);
TF2.setName("TF2");
TextField TF3 = new TextField("");
TF3.addActionListener(this);
TF3.setName("TF3");

//Buttons
Berechnen = new Button("Berechnen");
Berechnen.addActionListener(this);
Beenden = new Button("Beenden");
Beenden.addActionListener(this);

add(Lab1);
add(TF1);
add(Lab2);
add(TF2);
add(Lab3);
add(TF3);
add(Berechnen);
add(Beenden);
setVisible(true);
setResizable(false);
pack();
}

public static void main(String[] args)
{
Test Test1 = new Test();
}

public void actionPerformed(ActionEvent event)
{
;
if (event.getSource() == Berechnen)
{
//Wert3 = Wert1 + Wert2;
try
{
Wert1 = TF1.getText();
}
catch (Exception e) {
Wert1 = "1";
}
System.out.println(Wert1);
};
if (event.getSource() == Beenden)
{
System.exit(0);
};

}
}
[/PHP]

Thx

Hi,

als erstes würde ich auch mal vor der ersten Zeile ein import.

Dann habe ich das gewandelt, und es hat wunderbar funktioniert.

Also mal importieren, und weiter gucken.

Verwende Java 1.4, dürfte aber egal sein.

Also,

Sorry wenn ich das so sage, aber

1. Woher hast du die Klasse CloseableFrame?? Die hatte ich mir selbst erstellt!

2. hatte ich auch Java 1.4.0_01 benutzt und es hat nicht funktioniert!

Der Fehler liegt daran, dass ich zwar z.B. mit

TextField TF1;

eine Instanz anlege, das Objekt aber noch nicht!

Wenn man sich das "Objekt" TF1 z.B. mit System.out... ansieht, stellt man fest das es keine Werte (wie Psoition etc) enthält!

Wenn ich jetzt den "new" Operator anstelle ihn im Konstruktor aufzurufen, schon in der oben erwähnten Zeile aufrufe

also

TextField TF1 = new Textfield;

dann funktioniert mein Programm einwandfrei! (natürlich die entsprechende Zeile aus dem Konstruktor entfernen nicht vergessen :-) )

Gandalf

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.