• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problem "Exception in thread "main" java.lang"

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please help me is urgent I have encountered a problem in my project of end of study (I work with Eclipse)

here is the error: Exception in thread "main" java.lang.NullPointerException
at design3d.swing.PanneauLogement.<init>(PanneauLogement.java:25)

and here is the class where the error is triggered:



package design3d.swing;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.util.ResourceBundle;
import javax.swing.*;

import design3d.modele.*;

public class PanneauLogement extends JRootPane {

//Enumération des clés d?accès aux actions disponibles sur la vue.
public enum ActionType {UNDO, REDO, ADD_MEUBLE_LOGEMENT, DELETE_MEUBLE_LOGEMENT, DELETE, CREATE_WALLS}

private ResourceBundle resource;
private JToggleButton.ToggleButtonModel selectToggleModel;
private JToggleButton.ToggleButtonModel createWallsToggleModel;

public PanneauLogement(Logement logement, PreferencesUtilisateur preferences, ControleurLogement controleur) {

//Lecture du fichier de propriétés des actions.
this.resource = ResourceBundle.getBundle(PanneauLogement.class.getName());

this.selectToggleModel = new JToggleButton.ToggleButtonModel();
this.selectToggleModel.setSelected(controleur.getControleurPlan().getMode() == ControleurPlan.Mode.SELECTION);
this.createWallsToggleModel = new JToggleButton.ToggleButtonModel();
this.createWallsToggleModel.setSelected(controleur.getControleurPlan().getMode() == ControleurPlan.Mode.WALL_CREATION);

JPopupMenu.setDefaultLightWeightPopupEnabled(false);
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);

//Créations des actions de la vue.
createActions(controleur);

//Modification de la barre de menus.
setJMenuBar(getLogementMenuBar());

//Ajout de la barre d?outils et des panneaux à la vue.
getContentPane().add(getToolBar(), BorderLayout.NORTH);
getContentPane().add(getPanneauMeubleCatalogue(controleur));
getContentPane().add(getMainPane(logement, controleur));
}

//Crée les actions associées à cette vue, à partir des propriétés en ressource.
private void createActions(final ControleurLogement controleur) {

createAction(ActionType.UNDO,controleur, "undo");
createAction(ActionType.REDO, controleur, "redo");
createAction(ActionType.ADD_MEUBLE_LOGEMENT, controleur, "ajouterMeubleLogement");
createAction(ActionType.DELETE_MEUBLE_LOGEMENT, controleur.getControleurMeuble(), "effacerSelection");
}

private void createAction(ActionType action, Object controleur, String methode) {
try {
getActionMap().put(action, new ControleurAction(this.resource, action.toString(), controleur, methode));
}
catch (NoSuchMethodException ex) {
throw new RuntimeException(ex);
}
}

//Renvoie la barre de menus associée à cette vue.
private JMenuBar getLogementMenuBar() {
ActionMap actions = getActionMap();

//Création du menu Edition à partir de sa pseudo-action associée.
JMenu editMenu = new JMenu(new ResourceAction(this.resource, "EDIT_MENU"));
editMenu.setEnabled(true);

//Ajout des éléments du menu Edition configurés à partir de leur action.
editMenu.add(actions.get(ActionType.UNDO));
editMenu.add(actions.get(ActionType.REDO));

//Création du menu Meubles.
JMenu meubleMenu = new JMenu(new ResourceAction(this.resource, "FURNITURE_MENU"));
meubleMenu.setEnabled(true);

//Ajout des éléments du menu Meubles configurés à partir de leur action.
meubleMenu.add(actions.get(ActionType.ADD_MEUBLE_LOGEMENT));
meubleMenu.add(actions.get(ActionType.DELETE_MEUBLE_LOGEMENT));

//Création de la barre de menus avec les menus Edition, Meubles et Plan.
JMenuBar menuBar = new JMenuBar();
menuBar.add(editMenu);
menuBar.add(meubleMenu);

return menuBar;
}
//Renvoie la barre d?outils associée à cette vue.
private JToolBar getToolBar() {
JToolBar toolBar = new JToolBar();
ActionMap actions = getActionMap();

//Ajout des boutons à la barre d?outils dont les icônes et les listeners sont configurés à partir des actions associées à cette vue.
toolBar.add(actions.get(ActionType.ADD_MEUBLE_LOGEMENT));
toolBar.add(actions.get(ActionType.DELETE_MEUBLE_LOGEMENT));
toolBar.addSeparator();
toolBar.add(actions.get(ActionType.UNDO));
toolBar.add(actions.get(ActionType.REDO));
return toolBar;
}

//Active ou désactive l?action qui correspond à la clé actionType.
public void setEnabled(ActionType actionType, boolean enabled) {
getActionMap().get(actionType).setEnabled(enabled);
}

//Modifie le texte et la description courte des actions Annuler/Refaire.
public void setUndoRedoName(String undoText, String redoText) {
setNameAndShortDescription(ActionType.UNDO, undoText);
setNameAndShortDescription(ActionType.REDO, redoText);
}

private JComponent getPanneauMeubleCatalogue(ControleurLogement controleur) {

//Récupération des vues de l?arbre du catalogue et du tableau des meubles.
JComponent vueCatalogue = controleur.getControleurCatalogue().getVue();
JComponent vueMeuble = controleur.getControleurMeuble().getVue();

//Création d?un panneau partagé qui visualise les deux vues dans des panneaux à ascenseurs.
JSplitPane panneauMeubleCatalogue =new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(vueCatalogue), new JScrollPane(vueMeuble));

//Redimensionnement continu pendant le déplacement de la barre de division.
panneauMeubleCatalogue.setContinuousLayout(true);

//Affichage en un clic d?une ou de l?autre partie du panneau.
panneauMeubleCatalogue.setOneTouchExpandable(true);

//Changement du poids des composants du panneau partagé pour qu?après un redimensionnement du panneau, ils gardent les mêmes proportions verticalement
panneauMeubleCatalogue.setResizeWeight(0.5);
return panneauMeubleCatalogue;
}

//Renvoie le panneau principal ajouté au centre du composant HomePane dans son constructeur.
private JComponent getMainPane(Logement logement, ControleurLogement controleur) {

JSplitPane mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, getPanneauMeubleCatalogue(controleur), getPlanView3DPane(logement, controleur));
mainPane.setContinuousLayout(true);
mainPane.setOneTouchExpandable(true);
mainPane.setResizeWeight(0.3);
return mainPane;
}

//Renvoie le panneau qui contient la vue du plan et la vue 3D du logement.
private JComponent getPlanView3DPane(Logement logement, ControleurLogement controleur) {
JComponent planView = controleur.getControleurPlan().getVue();

//Création du composant de la vue 3D du logement.
JComponent view3D = new LogementComponent3D(logement);
view3D.setPreferredSize(planView.getPreferredSize());
view3D.setMinimumSize(new Dimension(0, 0));

//Ajout des deux composants dans un panneau partagé.
JSplitPane planView3DPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,new JScrollPane(planView), view3D);
planView3DPane.setContinuousLayout(true);
planView3DPane.setOneTouchExpandable(true);
planView3DPane.setResizeWeight(0.5);
return planView3DPane;
}
}




Of course there are other classes and this is the class constructor ControleurLogement:

public ControleurLogement(Logement logement, PreferencesUtilisateur preferences) {

this.logement = logement;
this.preferences = preferences;

this.undoSupport = new UndoableEditSupport();
this.undoManager = new UndoManager();
this.undoSupport.addUndoableEditListener(this.undoManager);

this.controleurCatalogue = new ControleurCatalogue(preferences.getCatalogue());

this.controleurMeuble = new ControleurMeuble(logement, preferences, this.undoSupport);

this.vueLogement = new PanneauLogement(logement, preferences, this);

ajouterListeners();
}


Important: The main method is in the class ControleurLogementTest

And finally, I thank you in advance for the attention you bring to this message
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TL;DR

You should start by figuring out which object reference is null. Some strategically placed System.out.println statements will help with that. Then go back in the code to find the spot where you think that reference should not be null. That should give you a starting point in figuring out where the code goes wrong.
 
Nacer Heithem
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:TL;DR

You should start by figuring out which object reference is null. Some strategically placed System.out.println statements will help with that. Then go back in the code to find the spot where you think that reference should not be null. That should give you a starting point in figuring out where the code goes wrong.



Hi,

I have added the following tests to identify what is causing the exception

if (this.selectToggleModel==null)
System.err.println("this.selectToggleModel==null");

if (controleur==null)
System.err.println("controleur==null");
else
if (controleur.getControleurPlan()==null)
System.err.println("controleur.getControleurPlan()==null");

this.selectToggleModel.setSelected(controleur.getControleurPlan().getMode() == ControleurPlan.Mode.SELECTION);



and here is the test result: controleur.getControleurPlan()==null


help me please and thank you in advance
 
Marshal
Posts: 79986
399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will have to go to coutroleur and find controleurPlan, and work out why that is null.
 
Nacer Heithem
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:You will have to go to coutroleur and find controleurPlan, and work out why that is null.




Ok I will try
 
Campbell Ritchie
Marshal
Posts: 79986
399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And never use the wordurgent” on this website (except possibly on 1st April )
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic