Eclipse错误(FNAF迷你游戏模拟)

时间:2015-04-08 16:03:36

标签: java eclipse

我有一个FNAF迷你游戏模拟的最后一个错误。这是关于非法争论的事情吗?

现在,这是我的错误:

Exception in thread "main" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(ImageIO.java:1388) at Minigame.<init>(Minigame.java:40) at Minigame.main(Minigame.java:140)

......这是我的代码(仅限一个类):

import java.awt.*; 
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;

public class Minigame extends JPanel
{   
private static final long serialVersionUID = 1L;

GameEvents gameEvents = new GameEvents();
Timer gameTimer = new Timer(1, gameEvents);
int i = 0; 
int horizontalposition = 500;
int verticalposition = 500;

BufferedImage Picture;
BufferedImage Picture2;
BufferedImage Picture3;
BufferedImage Picture4;
BufferedImage Picture5;
BufferedImage Picture6; 

//Don't forget to declare your variables!


Minigame() {
    gameTimer.start();
    this.addKeyListener(gameEvents);

    try 
    {

        System.out.println("Processing...");

        Picture = ImageIO.read(getClass().getResource("Child.gif"));
        Picture2 = ImageIO.read(getClass().getResource("Static_Background.jpg"));
        Picture3 = ImageIO.read(getClass().getResource("Purple_Person.png"));
        Picture4 = ImageIO.read(getClass().getResource("Cake_Child_Idle.png"));
        Picture5 = ImageIO.read(getClass().getResource("Freddy2.gif"));
        Picture6 = ImageIO.read(getClass().getResource("Freddy.gif"));
        //How do you use gifs?
        //The format for this is Picture = ImageIO.read(getClass().getResource("NameOfFile.typeoffile"));
    }
    catch (IOException e)
    {
        System.out.println("Pictures failed to load");
    }
}

@Override
protected void paintComponent(Graphics g)
{
    g.setColor(Color.black);
    g.fillRect(0,0,this.getWidth(), this.getHeight());

    ///g.drawImage(Picture, horizontalposition, verticalposition, 100, 150, null);
    g.drawImage(Picture2, 0, 0, 1500, 1700, null);
    g.drawImage(Picture, 200, 10, 70, 100, null);
    g.drawImage(Picture, 200, 100, 70, 100, null);
    g.drawImage(Picture, 200, 200, 70, 100, null);
    g.drawImage(Picture, 200, 300, 70, 100, null);
    g.drawImage(Picture, 200, 400, 70, 100, null);
    g.drawImage(Picture, 200, 500, 70, 100, null);
    g.drawImage(Picture3, 1100, 50, 100, 150, null);
    g.drawImage(Picture4, 1000, 100, 70, 100, null);
    g.drawImage(Picture6, horizontalposition, verticalposition, 100, 150, null);

}

public class GameEvents implements ActionListener, KeyListener
{
    @Override
    public void actionPerformed(ActionEvent arg0) 
    {
        repaint();
    }

    @Override
    public void keyPressed(KeyEvent key) //stuff inside here happens when a key is pressed
    {
        if(key.getKeyChar()=='d')
        {
            horizontalposition=horizontalposition+50;
        }
        if(key.getKeyChar()=='s')
        {
            verticalposition=verticalposition+50;
        }
        if(key.getKeyChar()=='w')
        {
            verticalposition=verticalposition-50;
        }
        if(key.getKeyChar()=='a')
        {
            horizontalposition=horizontalposition-50;
        }

        if(horizontalposition<200)
        {
            horizontalposition=200;
        }
        if(horizontalposition>900)
        {
            horizontalposition=900;
        }

        if(verticalposition<-50)
        {
            verticalposition=-50;
        }
        if(verticalposition>525)
        {
            verticalposition=525;
        }

        System.out.println(key.getKeyChar());
        System.out.println('d');
    }

    @Override
    public void keyReleased(KeyEvent arg0) {

    }

    @Override
    public void keyTyped(KeyEvent arg0) {
    }

}
public static void main(String[] args) 
{

    JFrame f = new JFrame("Java Graphics Example Project");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Minigame p = new Minigame();
    f.setSize(1500,700);
    System.out.println("Processer Complete.");
    f.add(p);
    System.out.println("IT'S ME.");
    f.setVisible(true);
    p.requestFocusInWindow();

    }

}

无论如何,我对Eclipse很新,所以请具体一点。谢谢你的帮助。

0 个答案:

没有答案