Help! mijn GUI verschijnt niet :(

  • Onderwerp starter Onderwerp starter Wim81
  • Startdatum Startdatum
Status
Niet open voor verdere reacties.

Wim81

Nieuwe gebruiker
Lid geworden
4 nov 2013
Berichten
1
Beste,

Ik moet een programma aanpassen en heb aldus een paar klassen toegevoegd. Een gelijkaardige klasse gekopieerd en de namen aangepast.
Nu wil ik men programma runnen en ik krijg het login scherm te zien, maar eens ingelogd en de gegevens geladen zie je in de login logschermpje dat de applicatie wordt opgestart, maar er komt geen GUI tevoorschijn!

In de error log krijg ik enkele nullpointerExceptions:

Code:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at be.fgov.economie.pharmacy.ui.model.table.ListStatsTableModel.<init>(ListStatsTableModel.java:32)
	at be.fgov.economie.pharmacy.ui.model.ListStatsPanelModel.<init>(ListStatsPanelModel.java:17)
	at be.fgov.economie.pharmacy.ui.view.MainTabbedPaneView.<init>(MainTabbedPaneView.java:117)
	at be.fgov.economie.pharmacy.ui.view.MainWindowView.initComponents(MainWindowView.java:155)
	at be.fgov.economie.pharmacy.ui.view.MainWindowView.<init>(MainWindowView.java:57)
	at be.fgov.economie.pharmacy.ui.controller.LoginController$2.run(LoginController.java:116)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(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)

Dit is de code van bvb de eerste nullpointer Exception:
Code:
package be.fgov.economie.pharmacy.ui.model.table;

import be.fgov.economie.pharmacy.entity.StatsEntity;

import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * @author <a href="mailto:thierry.paul@economie.fgov.be">Thierry PAUL</a>
 */
public class ListStatsTableModel extends AbstractTableModel {

    private Object[][] data;

    /**
     * number of columns of this model
     */
    public static final int COLUMNCOUNT = 8;
    public static final int NUM_FIRM_COLUMN_INDEX = 0;
    public static final int NAME_COLUMN_INDEX = 1;
    public static final int NAME_RESP_COLUMN_INDEX = 2;
    public static final int C_LANG_COLUMN_INDEX = 3;
    public static final int NOTEL_COLUMN_INDEX = 4;
    public static final int MEDICAMENT_LINK_COLUMN_INDEX = 5;
    public static final int DOSSIER_LINK_COLUMN_INDEX = 6;
    public static final int DOSSIER_ADD_LINK_COLUMN_INDEX = 7;

    private List<StatsEntity> list;

    public ListStatsTableModel(List<StatsEntity> list) {
        this.list = list;
        this.data = new Object[list.size()][COLUMNCOUNT];
        init();
        System.out.println(list);
    }
 
    /**
     * Returns the number of rows in the model. A
     * <code>JTable</code> uses this method to determine how many rows it
     * should display.  This method should be quick, as it
     * is called frequently during rendering.
     *
     * @return the number of rows in the model
     * @see #getColumnCount
     */
    @Override
    public int getRowCount() {
        return data.length;
    }

    /**
     * Returns the number of columns in the model. A
     * <code>JTable</code> uses this method to determine how many columns it
     * should create and display by default.
     *
     * @return the number of columns in the model
     * @see #getRowCount
     */
    @Override
    public int getColumnCount() {
        return COLUMNCOUNT;
    }

    /**
     * Returns the value for the cell at <code>columnIndex</code> and
     * <code>rowIndex</code>.
     *
     * @param rowIndex    the row whose value is to be queried
     * @param columnIndex the column whose value is to be queried
     * @return the value Object at the specified cell
     */
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return data[rowIndex][columnIndex];
    }

    /**
     * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
     *
     * @param columnIndex the column being queried
     * @return the Object.class
     */
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        if (columnIndex == NAME_RESP_COLUMN_INDEX) {
            return String.class;
        } else {
            return super.getColumnClass(columnIndex);
        }
    }

    /**
     * This empty implementation is provided so users don't have to implement
     * this method if their data model is not editable.
     *
     * @param aValue      value to assign to cell
     * @param rowIndex    row of cell
     * @param columnIndex column of cell
     */
    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        data[rowIndex][columnIndex] = aValue;
        fireTableCellUpdated(rowIndex, columnIndex);
    }

    /**
     * Returns false.  This is the default implementation for all cells.
     *
     * @param rowIndex    the row being queried
     * @param columnIndex the column being queried
     * @return false
     */
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return columnIndex == NAME_RESP_COLUMN_INDEX;
    }

    private void init() {
        int count = 0;
        for (StatsEntity stats : list) {
            data[count][NUM_FIRM_COLUMN_INDEX] = stats.getNumstats();
            data[count][NAME_COLUMN_INDEX] = new StatsInfo(stats.getName(),
                    stats.getRue(),
                    stats.getcPostal(),
                    stats.getCommune(),
                    stats.getPays());
            data[count][NAME_RESP_COLUMN_INDEX] = stats.getNomResp();
            data[count][C_LANG_COLUMN_INDEX] = stats.getcLang();
            data[count][NOTEL_COLUMN_INDEX] = stats.getNotel();
            count++;
        }
    }

    public List<StatsEntity> getList() {
        return list;
    }

    /**
     *
     */
    public static class StatsInfo {

        private String name;

        private String rue;

        private String cPostal;

        private String commune;

        private String pays;

        private StatsInfo(String name, String rue, String cPostal, String commune, String pays) {
            this.name = name;
            this.rue = rue;
            this.cPostal = cPostal;
            this.commune = commune;
            this.pays = pays;
        }

        public String getName() {
            return name;
        }

        public String getRue() {
            return rue;
        }

        public String getcPostal() {
            return cPostal;
        }

        public String getCommune() {
            return commune;
        }

        public String getPays() {
            return pays;
        }

        /**
         * Returns a string representation of the object. In general, the
         * <code>toString</code> method returns a string that
         * "textually represents" this object. The result should
         * be a concise but informative representation that is easy for a
         * person to read.
         * It is recommended that all subclasses override this method.
         * <p/>
         * The <code>toString</code> method for class <code>Object</code>
         * returns a string consisting of the name of the class of which the
         * object is an instance, the at-sign character `<code>@</code>', and
         * the unsigned hexadecimal representation of the hash code of the
         * object. In other words, this method returns a string equal to the
         * value of:
         * <blockquote>
         * <pre>
         * getClass().getName() + '@' + Integer.toHexString(hashCode())
         * </pre></blockquote>
         *
         * @return a string representation of the object.
         */
        @Override
        public String toString() {
            return name;
        }
    }

}

Weet iemand hier de oorzaak van? Wat moet ik aanpassen om opnieuw de GUI te zien, met hopelijk de toegevoegde functies?

Groetjes
Wim
 
Probeer hem is te debuggen door breakpoints neer te zetten en op het bug diertje de klikken.
Dit kan je helpen, ook als je in Eclipse erover een hovert (de waardes zoals String enzo) dan zie je wat ze op het breakpoint als waarde hebben. Dit kan handig zijn!
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan