Hi, I am doing a project on picture editing and i have a null pointer exception in blur and i can't find out what's wrongs.. AIn this project i only can load .bmp images below is the code. Help me pls.

Code:

Effect Class

import java.awt.image.BufferedImage;


public abstract class Effect 
{
	private BufferedImage image;
	
	public Effect (BufferedImage image)
	{
		this.setImage(image);
	}

	public Effect ()
	{}
	

	public void setImage(BufferedImage image) {
		this.image = image;
	}

	public BufferedImage getImage() {
		return image;
	}
	
	public abstract BufferedImage execute();


}

Blur Class

import java.awt.image.BufferedImage;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;


public class Blur extends Effect
{
	public Blur(BufferedImage image)
	{
		super(image);
	}
	
	/*public BufferedImage execute (BufferedImage image)
	{
		//float weight = 1.0f/9.0f;
		float weight = 1.0f/9.0f;
		
		float [] elements = {weight, weight, weight, weight, weight, weight, weight, weight, weight};
		
		Kernel k = new Kernel (3,3,elements);
		ConvolveOp op = new ConvolveOp(k);
		
		BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
		
		op.filter(image, dest);
		return dest;
	}*/
	@Override
	
	public BufferedImage execute() {
		// TODO Auto-generated method stub
		float weight = 1.0f/9.0f;
		
		float [] elements = {weight, weight, weight, weight, weight, weight, weight, weight, weight};
		
		Kernel k = new Kernel (3,3,elements);
		ConvolveOp op = new ConvolveOp(k);
		
		BufferedImage dest = new BufferedImage(getImage().getWidth(), getImage().getHeight(), getImage().getType());
		
		op.filter(getImage(), dest);
		return dest;
	}

}

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

The stack trace tells you exactly which line the exception occurs on. Read it and figure out why the variable you are calling a method on is null.

This article has been dead for over six months. Start a new discussion instead.