Home > Back-end >  About the Exception in the thread "main" Java. Lang. NullPointerException
About the Exception in the thread "main" Java. Lang. NullPointerException

Time:10-02

No error operation that is
Package UI;

Import the Java. The awt. Graphics;
The import config. ConfigFactory;
The import config. GameConfig;
The import config. LayerConfig;
Import the JDK. Nashorn. Internal. Runtime. Regexp. Joni. Config.

The import javax.mail. Swing. *;
Import the Java. The awt. *;
Import the Java. Lang. Reflect. The Constructor;
Import the Java. Lang. Reflect. InvocationTargetException;
Import the Java. Util. ArrayList;
import java.util.List;

Public class PanelGame extends JPanel {
Private List The layers=null;

Public PanelGame () {
//get the game configuration
Try {
GameConfig CFG=ConfigFactory. GetGameConfig ();
//get the layer configuration
List LayersCfg=CFG. GetLayersConfig ();
//create an array of game layer
The layers=new ArrayList (layersCfg. The size ());
For (layerConfig layerCfg: layersCfg) {
//get the class object
Class<?> CLS=Class. Class.forname (layerCfg getClassName ());
Constructor<?> CTR=CLS. GetConstructor (int. Class, int. J class, int. J class, int. J class);
Layer l=(Layer) CTR. NewInstance (
LayerCfg. GetX (), layerCfg getY (), layerCfg. GetW (), layerCfg. GetH ()
);
The layers. The add (l);
}


{} to catch (a ClassNotFoundException | NoSuchMethodException e)
e.printStackTrace();
///the layers=new Layer [] {
///new LayerBreakground,0,0,0 (0),
///new LayerDateBase (40, 32, 334, 279),
///new LayerDisk (40, 343, 334, 279),
///new LayerGame (414, 32, 334, 590),
///new LayerButton (788, 32, 334, 124),
///new LayerNext (788, 188, 176, 148),
///new LayerLevel (964, 188, 158, 148),
///new LayerPoint (788, 368, 334, 200)
///};
} the catch (IllegalAccessException e) {
e.printStackTrace();
} the catch (InstantiationException e) {
e.printStackTrace();
} the catch (InvocationTargetException e) {
e.printStackTrace();
}
}
Public void paintComponent (Graphics g) {
//loop refresh window
for(int i=0; I//refresh the layer window
The layers. The get (I). Paint (g);
///}
}}}
Package UI;

The import javax.mail. Swing. *;
Import the Java. The awt. *;

Public class FrameGame extends JFrame {
Public FrameGame () {
//set the title
Enclosing setTitle (" tetris ");
//set off by default
Enclosing setDefaultCloseOperation (JFrame. EXIT_ON_CLOSE);
//window size
Enclosing setSize (1150650);
//the user cannot change size
Enclosing setResizable (false);
//center
Enclosing setLocationRelativeTo (null);
The Toolkit Toolkit=Toolkit. GetDefaultToolkit ();
Dimension screen=toolkit. GetScreenSize ();
Int x=(screen width - this. GetWidth ())/2;
Int y=(screen height - this. GetHeight ())/2-30;
Enclosing setLocation (x, y);
//set the default panel
Enclosing setContentPane (new PanelGame ());
}
}

Package the main;

The import of the UI. FrameGame;

Import the Java. The awt. *;

Public class Main {
Public static void main (String [] args) {

New FrameGame (.) setVisible (true);

}
}

CodePudding user response:

Without exception to stick out, if it is a null pointer, you can see which line's thrown out,

CodePudding user response:

reference 1/f, password test response:
without exception to stick out, if it is a null pointer, you can see which line's thrown out,
Java lang. ClassNotFoundException: UI. LayerBackground
The at java.net.URLClassLoader.findClass URLClassLoader. Java: (382)
The at Java. Lang. This. LoadClass (418). This Java:
At sun. Misc. The Launcher $AppClassLoader. LoadClass (355). The Launcher Java:
The at Java. Lang. This. LoadClass (351). This Java:
The at Java. Lang. Class. ForName0 (Native Method)
The at Java. Lang. Class.forname (264) Class. Java:
At the UI. PanelGame. & lt; init> (PanelGame. Java: 29)
At the UI. FrameGame. & lt; init> (FrameGame. Java: 24)
At the main. The main. The main (the main Java: 10)

The Process finished with exit code 0
  • Related