I've tried going to the original Null Pointer Exception question, but it didn't help. Here is the first and second line of the stack trace:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Client.SpriteField.paintComponent(SpriteField.java:30)
So this is telling me that it is in the package "Client", the class "SpriteField", and the method "paintComponent" right? Here is the code in the class SpriteField:
package Client;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import javax.swing.JPanel;
public class SpriteField extends JPanel
{
RoundSprite mSprite;
public void CreateSpriteAt(float tX, float tY, int tWidth, int tHeight, int tRotation)
{
mSprite = new RoundSprite();
mSprite.SetPosition(tX, tY);
mSprite.SetSpriteWidth(tWidth);
mSprite.SetSpriteHeight(tHeight);
mSprite.SetSpriteRotation(tRotation);
}
public void paintComponent (Graphics g)
{
if(g != null)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
AffineTransform tOldTransform = g2.getTransform();
mSprite.DrawSprite(g2);
g2.setTransform(tOldTransform);
}
}
}
It might have been just a careless mistake, but I can't seem to find it. Please help, thanks for your time.
EDIT: As asked, here is the main method:
final SpriteField mSpritePanel = new SpriteField();
mSpritePanel.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
float tX = e.getX();
float tY = e.getY();
if(tTextWidth.getText() == null)
{
tTextWidth.setText("50");
}
int tIntWidth = Integer.parseInt(tTextWidth.getText());
if(tIntWidth == 0)
{
tIntWidth = 50;
}
if(tTextHeight.getText() == null)
{
tTextHeight.setText("50");
}
int tIntHeight = Integer.parseInt(tTextHeight.getText());
if(tIntHeight == 0)
{
tIntHeight = 50;
}
int tRotate = Integer.parseInt(tTextRotation.getText());
mSpritePanel.CreateSpriteAt(tX, tY, tIntWidth, tIntHeight, tRotate);
mSpritePanel.repaint();
}
});