Я строю проект, используя Spring Framework.В бине я создал класс Model
, затем я использую его в классе Menu
true бывал (метод get и set).Он показывает NULL EXCEPTION
, я проверил его, и мой класс null
.Почему я создал его с помощью бобов ...?Помогите.В классе Menu line 61
bean:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="controller"
class="com.videogame.invasion.controller.Controller">
<property name="model" ref="model"></property>
<property name="frame" ref="frame"></property>
</bean>
<bean id="frame" class="com.videogame.invasion.view.Frame">
<property name="container" ref="container"></property>
</bean>
**<bean id="container" class="com.videogame.invasion.view.Menu">**
<property name="play" ref="play"></property>
<property name="creditsView" ref="creditsView"></property>
<property name="highScoreView" ref="highScoreView"></property>
**<property name="model" ref="model"></property>**
</bean>
<bean id="creditsView"
class="com.videogame.invasion.view.CreditsView">
</bean>
<bean id="highScoreView"
class="com.videogame.invasion.view.HighScoreView">
</bean>
<bean id="play" class="com.videogame.invasion.view.play.Play">
<property name="shipsFactory" ref="shipsFactory"></property>
</bean>
<bean id="shipsFactory"
class="com.videogame.invasion.view.play.ShipsFactory">
<property name="enemyShip" ref="enemyShip"></property>
<property name="playerShip" ref="playerShip"></property>
</bean>
<bean id="playerShip"
class="com.videogame.invasion.view.play.PlayerShip">
</bean>
<bean id="enemyShip"
class="com.videogame.invasion.view.play.EnemyShip">
</bean>
<bean id="model" class="com.videogame.invasion.model.Model">
<property name="save" ref="save"></property>
<property name="load" ref="load"></property>
<property name="loadHighScore" ref="loadHighScore"></property>
<property name="saveHighScore" ref="saveHighScore"></property>
</bean>
<bean id="save" class="com.videogame.invasion.model.SaveGame"></bean>
<bean id="load" class="com.videogame.invasion.model.LoadGame"></bean>
<bean id="loadHighScore"
class="com.videogame.invasion.model.LoadHighScore">
</bean>
<bean id="saveHighScore"
class="com.videogame.invasion.model.SaveHighScore">
</bean>
Модель класса, когда я ее запускаю, показывает мне значение System.out.println ("AAAAAA")что класс создан.
Меню:
package com.videogame.invasion.view;
public class Menu extends JPanel implements ActionListener{
private Controller controller;
private Model model;
private CreditsView creditsView;
private HighScoreView highScoreView;
private Play play;
private JButton newGame, loadGame, highScore, credits, exit, back, save;
private int buttonHeight = 20;
private int buttonWidth = 120;
private Image image;
public Menu() {
setLayout(null);
setButtons();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == newGame) {
} else if (e.getSource() == loadGame) {
} else if (e.getSource() == highScore) {
System.out.println("test AP MENU");
if (model == null) {
System.out.println("model is null");
}else {
**model.test();** LINE 61 !!
}
} else if (e.getSource() == credits) {
} else if (e.getSource() == exit) {
}
}
public Model getModel() {
return model;
}
public void setModel(Model model) {
this.model = model;
}
}
Модель:
package com.videogame.invasion.model;
public class Model {
private LoadGame load;
private SaveGame save;
private SaveHighScore saveHighScore;
private LoadHighScore loadHighScore;
public Model() {
System.out.println("AAAAAA");
}
public void test() {
System.out.println("TEST");
}
}