Hallo Leute,
ich hab ne Aufgabe von der Schule, die Seite Mobile.de nachzuprogrammieren und momentan hänge ich an der Garage fest. Und zwar habe ich ein HauptGUI, von der man sich in die Garage klicken kann. Dann öffnet sich die GarageGUI aber wenn ich wieder zum HauptGUI zurückkehren will, sprich auf den Button "zum Hauptprogramm" klicke, dann gibt mir die Konsole tausend Fehler aus:
und da ich ein absoluter Anfänger bin und so gut wie keine Ahnung hab, komm ich nicht weiter! :-( Ich hab mich mal durch die Exceptions geklickt, aber ich komm einfach nicht drauf, was da falsch ist!
Hier meine GarageGUI und mein HauptGUI:
Kann mir da jemand weiterhelfen?
ich hab ne Aufgabe von der Schule, die Seite Mobile.de nachzuprogrammieren und momentan hänge ich an der Garage fest. Und zwar habe ich ein HauptGUI, von der man sich in die Garage klicken kann. Dann öffnet sich die GarageGUI aber wenn ich wieder zum HauptGUI zurückkehren will, sprich auf den Button "zum Hauptprogramm" klicke, dann gibt mir die Konsole tausend Fehler aus:
Code:
java.lang.NullPointerException
at GarageGUI.jButton4ActionPerformed(GarageGUI.java:176)
at GarageGUI.access$400(GarageGUI.java:15)
at GarageGUI$5.actionPerformed(GarageGUI.java:148)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
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)
und da ich ein absoluter Anfänger bin und so gut wie keine Ahnung hab, komm ich nicht weiter! :-( Ich hab mich mal durch die Exceptions geklickt, aber ich komm einfach nicht drauf, was da falsch ist!
Hier meine GarageGUI und mein HauptGUI:
Code:
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class GarageGUI extends javax.swing.JFrame
{
public HauptGUI hauptGUI;
public SuchenGUI einSuchenGUI;
public Fahrzeug fahrzeug;
public Benutzer referenzBenutzer;
private boolean konst1 = true;
/** Creates new form GarageGUI */
public GarageGUI(HauptGUI pHauptGUI, Fahrzeug pFahrzeug, Benutzer pBenutzer)
{
initComponents();
hauptGUI = pHauptGUI;
fahrzeug = pFahrzeug;
referenzBenutzer = pBenutzer;
String sTyp;
konst1 = true;
if(fahrzeug.isPkw())
sTyp = "PKW";
else
sTyp = "Motorrad";
jTextArea1.setText("Fahrzeugtyp:"+"\t"+ sTyp+"\t"
+"Marke:\t"+fahrzeug.getMarke()+"\n\n\n"
+"Modell:\t"+fahrzeug.getModell()+"\t"
+"Kategorie:\t"+fahrzeug.getKategorie()+"\n\n\n"
+"Motorleistung:\t"+fahrzeug.getMotorleistung()+"\t"
+"Fahrleistung:\t"+fahrzeug.getFahrleistung()+"\n\n\n"
+"Hubraum:\t"+fahrzeug.getHubraum()+"\t"
+"Farbe:\t"+fahrzeug.getFarbe()+"\n\n\n"
+"Baujahr:\t"+fahrzeug.getBaujahr()+"\t"
+"Verkaufspreis:\t"+fahrzeug.getVerkaufspreis()+"\n\n\n"
+"Beschreibung:\t"+fahrzeug.getBeschreibung()+"\t");
jTextArea1.setEditable(false);
}
public GarageGUI(SuchenGUI pSuchenGUI, Fahrzeug pFahrzeug, Benutzer pBenutzer)
{
initComponents();
hauptGUI = pSuchenGUI.getHauptGUI();
einSuchenGUI = pSuchenGUI;
fahrzeug = pFahrzeug;
referenzBenutzer = pBenutzer;
String sTyp;
konst1 = false;
jButton1.setVisible(false);
if(fahrzeug.isPkw())
sTyp = "PKW";
else
sTyp = "Motorrad";
jTextArea1.setText("Fahrzeugtyp:"+"\t"+ sTyp+"\t"
+"Marke:\t"+fahrzeug.getMarke()+"\n\n\n"
+"Modell:\t"+fahrzeug.getModell()+"\t"
+"Kategorie:\t"+fahrzeug.getKategorie()+"\n\n\n"
+"Motorleistung:\t"+fahrzeug.getMotorleistung()+"\t"
+"Fahrleistung:\t"+fahrzeug.getFahrleistung()+"\n\n\n"
+"Hubraum:\t"+fahrzeug.getHubraum()+"\t"
+"Farbe:\t"+fahrzeug.getFarbe()+"\n\n\n"
+"Baujahr:\t"+fahrzeug.getBaujahr()+"\t"
+"Verkaufspreis:\t"+fahrzeug.getVerkaufspreis()+"\n\n\n"
+"Beschreibung:\t"+fahrzeug.getBeschreibung()+"\t");
}
public GarageGUI()
{
initComponents();
}
public static void main(String args[])
{
new GarageGUI().show();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
getContentPane().setLayout(null);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jTextArea1.setEditable(false);
getContentPane().add(jTextArea1);
jTextArea1.setBounds(60, 20, 360, 180);
jButton1.setText("Fahrzeug parken");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(40, 230, 150, 25);
jButton2.setText("Fahrzeug loeschen");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(40, 270, 150, 25);
jButton3.setText("Zur Suche");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
getContentPane().add(jButton3);
jButton3.setBounds(200, 270, 170, 25);
jButton4.setText("Zum Hauptprogramm");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
getContentPane().add(jButton4);
jButton4.setBounds(200, 230, 170, 25);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-484)/2, (screenSize.height-409)/2, 484, 409);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
hauptGUI.setEnabled(true);
this.dispose();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration
}
Code:
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class HauptGUI extends javax.swing.JFrame {
/** Creates new form BenutzerGUI */
public HauptGUI(Benutzer pBenutzer) {
user = pBenutzer;
initComponents();
setSize(500,500);
}
public HauptGUI()
{
initComponents();
}
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
getContentPane().setLayout(null);
setName("frame");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
jLabel1.setText("Hauptprogramm");
getContentPane().add(jLabel1);
jLabel1.setBounds(180, 10, 100, 20);
jLabel1.setFont(new Font("Arial Narrow",Font.BOLD,12));
jButton3.setText("Neues Angebot erstellen");
jButton3.setFont(new Font("Arial Narrow",Font.BOLD,12));
jButton3.setBounds(130, 305, 180, 20);
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
getContentPane().add(jButton3);
jButton4.setText("Zur Garage");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
getContentPane().add(jButton4);
jButton4.setBounds(20, 340, 170, 20);
jButton4.setFont(new Font("Arial Narrow",Font.BOLD,12));
jButton5.setText("geparkte Fahrzeuge ansehen");
jButton5.setFont(new Font("Arial Narrow",Font.BOLD,12));
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
getContentPane().add(jButton5);
jButton5.setBounds(220, 340, 180, 20);
jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.setViewportView(jList1);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(30, 50, 440, 240);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-500)/2, (screenSize.height-500)/2, 500, 500);
}
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
GarageGUI eineGarageGUI;
eineGarageGUI = new GarageGUI();
eineGarageGUI.show();
this.setEnabled(false);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
NeuesAngebotGUI einNeuesAngebotGUI;
einNeuesAngebotGUI = new NeuesAngebotGUI( this, user );
einNeuesAngebotGUI.show();
this.setEnabled(false);
}
/** Exit the Application */
private void exitForm(java.awt.event.WindowEvent evt) {
System.exit(0);
}
public static void main(String args[]) {
new HauptGUI().show();
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
private Benutzer user;
public JList getListe()
{
return jList1;
}
}
Kann mir da jemand weiterhelfen?