Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
public class Klasse1 implements ActionListener
{
private int eineVariable = 0;
....
public int getVariable(){
return this.eineVariable;
}
....
public void actionPerformed(ActionEvent e){
this.eineVariable = 1;
}
}
public class Klasse1 implements ActionListener
{
private Klasse2 andereKlasse;
....
public void actionPerformed(ActionEvent e){
int eineVariable = 1;
andereKlasse.setVariable(eineVariable);
}
}
public class Klasse2
int eineVariable;
public void setVariable(int inVariable){
this.eineVariable = inVariable;
}
}
public class Klasse1
extends Applet {
double b;
public Klasse2 Test;
...
public double Variable() {
try {
b = Double.parseDouble(textField1.getText());
System.err.println("b aus Variable = " + b); // b = 44.0
}
catch (NumberFormatException e) {
b = 0;
}
return b;
}
public void button1actionPerformed(ActionEvent e) {
b = Variable();
System.err.println("b aus Variable = " + b); // b = 44.0
Test.setVariable(b); // <---Hier kommt die NullPoitnerException
Klasse2 frame = new Klasse2();
...
}
}
public class Klasse2
extends Frame {
double c;
public void setVariable(double inVariable) {
this.c = inVariable;
System.err.println(c);
}
public Klasse2() {
}
public void paint(Graphics g) {
g.setColor(Color.blue);
g.drawLine(50, 60, 50 + (int) c, 60);
g.drawString("" + (int) c, 50, 50);
}
public void main(String[] args) {
}
}
Test.setVariable(b);
Klasse2 frame = new Klasse2();
01 class Satz_button1_actionAdapter
02 implements java.awt.event.ActionListener {
03 Klasse1 adaptee;
04 Satz_button1_actionAdapter(Klasse1 adaptee) throws IOException {
05 this.adaptee = adaptee;
06 }
07 public void actionPerformed(ActionEvent e) {
08 adaptee.button1actionPerformed(e);
09 }
10 }
java.lang.NullPointerException
at wertübergabe.Klasse1.button1actionPerformed(Klasse1.java:89)
at wertübergabe.Satz_button1_actionAdapter.actionPerformed(Klasse1.java:8)
at java.awt.Button.processActionEvent(Button.java:382)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)