Java.lang.NullPointerException

Fermé
Anonymous - 3 avril 2012 à 00:31
 Utilisateur anonyme - 3 avril 2012 à 09:38
Bonsoir, j'ai une petite erreur qui emperche de compiler mon programme, et j'ai besoin de votre aide svp..

L'erreur est une "java.lang.NullPointerException"

Exception in thread "main" java.lang.NullPointerException
at view.TaskPane$DemoPanel.<init>(TaskPane.java:172)
at view.TaskPane.<init>(TaskPane.java:33)
at view.TaskPane.main(TaskPane.java:292)


Voila Le code "TaskPane.java"

==================================
package view;

import com.l2fprod.common.swing.*;
import com.l2fprod.common.swing.plaf.LookAndFeelAddons;
import com.l2fprod.common.swing.plaf.aqua.AquaLookAndFeelAddons;
import com.l2fprod.common.util.ResourceManager;

import java.awt.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class TaskPane extends JPanel {

private Workspace parent;

static ResourceManager RESOURCE;

private JEditorPane propertiesText;

private DemoPanel demo;

public TaskPane() throws Exception {
RESOURCE = ResourceManager.get(TaskPane.class);
setLayout(new BorderLayout());

this.setBackground(Color.BLACK);

UIManager.put("win.xpstyle.name", null);

LookAndFeelAddons.setAddon(AquaLookAndFeelAddons.class);
DemoPanel demo = new DemoPanel();

add("Center", demo);
}

public TaskPane(Workspace parent) throws Exception {
RESOURCE = ResourceManager.get("view/TaskPaneRB");
this.parent = parent;

setLayout(new BorderLayout());

this.setBackground(Color.BLACK);

UIManager.put("win.xpstyle.name", null);

LookAndFeelAddons.setAddon(AquaLookAndFeelAddons.class);
demo = new DemoPanel();

add("Center", demo);
}

public void setTaskPaneBackground(Color c) {
demo.setTaskPaneBackground(c);
}

public Color getTaskPaneBackground() {
return demo.getTaskPaneBackground();
}

public DemoPanel getDemoPanel() {
return demo;
}

public Dimension getPreferredSize() {
return new Dimension(280, 400);
}

public JEditorPane getPropertyText() {
return propertiesText;
}

protected void doAction(String title) {
System.out.println("Commande: " + title);
if (title.equals(RESOURCE.getString("Main.tasks.addnode"))) {
parent.addNode();
} else if (title.equals(RESOURCE.getString("Main.tasks.addconnection"))) {
parent.addConection();
} else if (title.equals(RESOURCE.getString("Main.tasks.editnode"))) {
parent.editNode();
} else if (title.equals(RESOURCE.getString("Main.tasks.editconnection"))) {
parent.editConnection();
} else if (title.equals(RESOURCE.getString("Main.tasks.deletenode"))) {
parent.removeNode();
} else if (title.equals(RESOURCE.getString("Main.tasks.deleteconnection"))) {
parent.removeLink();
} else if (title.equals(RESOURCE.getString("Main.tasks.getgraphprop"))) {
parent.showGraphProperties();
} else if (title.equals(RESOURCE.getString("Main.tasks.getmatriceadj"))) {
parent.showMatriceAdjacence();
} else if (title.equals(RESOURCE.getString("Main.tasks.getlistadj"))) {
parent.showListeAdjacence();
} else if (title.equals(RESOURCE.getString("Main.tasks.fermTrans"))) {
parent.executeFermetureTransitive();
} else if (title.equals(RESOURCE.getString("Main.tasks.compConnexe"))) {
parent.executeComposanteConnexe();
} else if (title.equals(RESOURCE.getString("Main.tasks.compFortConnexe"))) {
parent.executeComposanteFortementConnexe();
} else if (title.equals(RESOURCE.getString("Main.tasks.cheminEulerien"))) {
parent.executeCheminEulerien();
} else if (title.equals(RESOURCE.getString("Main.tasks.circuitEulerien"))) {
parent.executeCircuitEulerien();
} else if (title.equals(RESOURCE.getString("Main.tasks.chaineEulerien"))) {
parent.executeChaineEulerienne();
} else if (title.equals(RESOURCE.getString("Main.tasks.cycleEulerien"))) {
parent.executeCycleEulerien();
} else if (title.equals(RESOURCE.getString("Main.tasks.ordonnancement"))) {
parent.executeOrdonnancement();
} else if (title.equals(RESOURCE.getString("Main.tasks.parcoursprof"))) {
parent.showParcoursProfondeur();
} else if (title.equals(RESOURCE.getString("Main.tasks.parcourslarg"))) {
parent.showParcoursLargeur();
} else if (title.equals(RESOURCE.getString("Main.tasks.algoBellman"))) {
parent.executeAlgoBellman();
} else if (title.equals(RESOURCE.getString("Main.tasks.algoDijkstra"))) {
parent.executeAlgoDijkstra();
} else if (title.equals(RESOURCE.getString("Main.tasks.algoBellmanFord"))) {
parent.executeBellmanFord();
} else if (title.equals(RESOURCE.getString("Main.tasks.algoKruskal"))) {
parent.executeKruskal();
} else if (title.equals(RESOURCE.getString("Main.tasks.algoPrim"))) {
parent.executeAlgoPrim();
}
}

class DemoPanel extends JTaskPane {

private JTaskPane taskPane;

private JTaskPaneGroup graphGroup, actionGroup, algoGroup,
propertiesGroup;

public Color getTaskPaneBackground() {
return taskPane.getBackground();
}

public void setTaskPaneBackground(Color c) {
taskPane.setBackground(c);
}

public DemoPanel() {
taskPane = new JTaskPane();
taskPane.setBackground(Color.BLACK);

// "Gestion des fichiers"
graphGroup = new JTaskPaneGroup();
graphGroup.setTitle(RESOURCE.getString("Main.tasks.graphManager"));
graphGroup.setToolTipText(RESOURCE.getString("Main.tasks.graphManager.tooltip"));
graphGroup.setSpecial(true);
graphGroup.setIcon(new ImageIcon("images/graphe.png"));

graphGroup.add(makeAction(RESOURCE.getString("Main.tasks.addnode"), "", "images/plus.png"));
graphGroup.add(makeAction(RESOURCE.getString("Main.tasks.addconnection"), "", "images/plus.png"));
graphGroup.add(makeAction(RESOURCE.getString("Main.tasks.editnode"), "", "images/edit.png"));
graphGroup.add(makeAction(RESOURCE.getString("Main.tasks.editconnection"), "", "images/edit.png"));
graphGroup.add(makeAction(RESOURCE.getString("Main.tasks.deletenode"), "", "images/minus.png"));
graphGroup.add(makeAction(RESOURCE.getString("Main.tasks.deleteconnection"), "", "images/minus.png"));

taskPane.add(graphGroup);

// Groupe "action"
actionGroup = new JTaskPaneGroup();
actionGroup.setTitle(RESOURCE.getString("Main.tasks.actionManager"));
actionGroup.setToolTipText(RESOURCE.getString("Main.tasks.actionManager.tooltip"));
actionGroup.setIcon(new ImageIcon("images/actions.png"));

actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.getgraphprop"), "", "images/pte.png"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.getmatriceadj"), "", "images/matadj.png"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.getlistadj"), "", "images/listadj.png"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.fermTrans"), "", "images/find.gif"));
if (parent.isOrientedGraph()) {
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.compFortConnexe"), "", "images/find.gif"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.cheminEulerien"), "", "images/find.gif"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.circuitEulerien"), "", "images/find.gif"));
} else {
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.compConnexe"), "", "images/find.gif"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.chaineEulerien"), "", "images/find.gif"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.cycleEulerien"), "", "images/find.gif"));
}
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.ordonnancement"), "", "images/find.gif"));

taskPane.add(actionGroup);

// Groupe "Algorithme"
algoGroup = new JTaskPaneGroup();
algoGroup.setTitle(RESOURCE.getString("Main.tasks.algorithmManager"));
algoGroup.setToolTipText(RESOURCE.getString("Main.tasks.algorithmManager.tooltip"));
algoGroup.setIcon(new ImageIcon("images/algorithms.png"));
algoGroup.setExpanded(false);

algoGroup.add(makeAction(RESOURCE.getString("Main.tasks.parcoursprof"), "", "images/parcoursprof.png"));
algoGroup.add(makeAction(RESOURCE.getString("Main.tasks.parcourslarg"), "", "images/parcourslarg.png"));
algoGroup.add(makeAction(RESOURCE.getString("Main.tasks.algoBellman"), "", "images/algo.png"));
algoGroup.add(makeAction(RESOURCE.getString("Main.tasks.algoDijkstra"), "", "images/algo.png"));
algoGroup.add(makeAction(RESOURCE.getString("Main.tasks.algoBellmanFord"), "", "images/algo.png"));
algoGroup.add(makeAction(RESOURCE.getString("Main.tasks.algoKruskal"), "", "images/algo.png"));
algoGroup.add(makeAction(RESOURCE.getString("Main.tasks.algoPrim"), "", "images/algo.png"));

taskPane.add(algoGroup);

// "Propriétés" GROUP
propertiesGroup = new JTaskPaneGroup();
propertiesGroup.setTitle(RESOURCE.getString("Main.tasks.properties"));
propertiesGroup.setToolTipText(RESOURCE.getString("Main.tasks.properties.tooltip"));
propertiesGroup.setIcon(new ImageIcon("images/propertysheet.png"));
propertiesGroup.setScrollOnExpand(true);

propertiesText = new PropertyObject(this);
propertiesGroup.add(propertiesText);

taskPane.add(propertiesGroup);

JScrollPane scroll = new JScrollPane(taskPane);
scroll.setBorder(null);

setLayout(new BorderLayout());
add("Center", scroll);

setBorder(null);
}

Action makeAction(String title, String tooltiptext, String iconPath) {
Action action = new AbstractAction(title) {
public void actionPerformed(ActionEvent e) {
System.out
.println("Action: <" + e.getActionCommand() + ">");
System.out.flush();
doAction(e.getActionCommand());
}
};
action.putValue(Action.SMALL_ICON, new ImageIcon(iconPath));
action.putValue(Action.SHORT_DESCRIPTION, tooltiptext);
return action;
}

public void updateTaskPane() {
taskPane.remove(actionGroup);
taskPane.remove(algoGroup);
taskPane.remove(propertiesGroup);

actionGroup = new JTaskPaneGroup();
actionGroup.setTitle(RESOURCE.getString("Main.tasks.actionManager"));
actionGroup.setToolTipText(RESOURCE.getString("Main.tasks.actionManager.tooltip"));
URL url = this.getClass().getResource("../images/actions.png");
actionGroup.setIcon(new ImageIcon(url));

actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.getgraphprop"), "","images/pte.png"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.getmatriceadj"), "","images/matadj.png"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.getlistadj"), "","images/listadj.png"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.fermTrans"), "", "images/find.gif"));
if (parent.isOrientedGraph()) {
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.compFortConnexe"), "", "images/find.gif"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.cheminEulerien"), "", "images/find.gif"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.circuitEulerien"), "", "images/find.gif"));
} else {
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.compConnexe"), "", "images/find.gif"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.chaineEulerien"), "", "images/find.gif"));
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.cycleEulerien"), "", "images/find.gif"));
}
actionGroup.add(makeAction(RESOURCE.getString("Main.tasks.ordonnancement"), "", "images/find.gif"));

taskPane.add(actionGroup);
taskPane.add(algoGroup);
taskPane.add(propertiesGroup);

taskPane.validate();
}

JTaskPaneGroup getGraphGroup() {
return graphGroup;
}

JTaskPaneGroup getActionGroup() {
return actionGroup;
}

JTaskPaneGroup getAlgoGroup() {
return algoGroup;
}

JTaskPaneGroup getPropertiesGroup() {
return propertiesGroup;
}
}

public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

JFrame frame = new JFrame("Mon JTaskPane à moi tout seul");
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add("Center", new TaskPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocation(100, 100);
frame.setVisible(true);
}

}

===============================================




1 réponse

Salut,

Si le code que tu compiles est strictement le même que celui que tu postes, la ligne 172 est la suivante:

172 graphGroup.setIcon(new ImageIcon("images/graphe.png"));

Sinon étant donné qu'on ne peut pas compiler n'ayant pas, entre autres choses, les "import com.l2fprod"... on ne peut pas vérifier quelle ligne provoque l'exception NullPointerException.

Est-ce que images est un répertoire du répertoire de travail ?

Cordialement,

Dan
Plus on apprend... plus on se rend compte qu'on ne connaît pas grand-chose.
0