package music_game_1;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Musicgame extends JFrame {
private Image screen_Image;
private Graphics screen_Graphic;
private ImageIcon backimage = new ImageIcon(Main.class.getResource("../Images/backimage.png"));
private ImageIcon backimagebasic = new ImageIcon(Main.class.getResource("../Images/backimgaebasic.png"));
public Musicgame() {
setUndecorated(true);
setTitle("Musicgame");
setSize(Main.SCREEN_WIdTH, Main.SCREEN_HEIGH);
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setBackground(new Color(0, 0, 0, 0));
setLayout(null);
backButton.setBounds(1895, 0, 30, 30);
backButton.setBorderPainted(false);
backButton.setContentAreaFilled(false);
backButton.setFocusPainted(false);
backButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
backButton.setIcon(backimage);
}
@Override
public void mouseExited(MouseEvent e) {
backButton.setIcon(backimagebasic);
}
@Override
public void mousePressed(MouseEvent e) {
System.exit(0);
}
});
add(backButton);
```
I'm making a rhythm game. Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at music_game_1.Musicgame.<init>(Musicgame.java:21)
at music_game_1.Main.main(Main.java:10)
I got this error, but when I looked it up,
- Causes: Occurs when you try to use a null object without creating an instance after you create an object to use. I don't know how to fix it. Is there anyone who can solve this?"T"
It looks like you made a typo!
backimgaebasic => backimagebasic
© 2024 OneMinuteCode. All rights reserved.