I am using drjava-stable-20090821-r5004, Java 6, and Windows Vista (Service Pack 1)
When Dr. Java tries to call greyscale() method "Pixel[] pixelArray = this.getPixels();"
Windows XP runs "Picture.java" fine. When you try and run the same class in Windows Vista,
the following error occurs:
Increase Maximum Heap Size?
Your program ran out of memory. You may try to enter a larger maximum heap size for the interactions JVM.
The maximum heap size is currently not set, implying the system's default. A restart is required after changing
this setting. "default"
This is the code I'm trying to compile and run (picture.java):
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.text.*;
import java.util.*;
import java.util.List; // resolves problem with java.awt.List and java.util.List
/**
* A class that represents a picture. This class inherits from
* SimplePicture and allows the student to add functionality to
* the Picture class.
*
* Copyright Georgia Institute of Technology 2004-2005
* @author Barbara Ericson ericson@cc.gatech.edu
*/
public class Picture extends SimplePicture
{
///////////////////// constructors //////////////////////////////////
/**
* Constructor that takes no arguments
*/
public Picture ()
{
/* not needed but use it to show students the implicit call to super()
* child constructors always call a parent constructor
*/
super();
}
/**
* Constructor that takes a file name and creates the picture
* @param fileName the name of the file to create the picture from
*/
public Picture(String fileName)
{
// let the parent class handle this fileName
super(fileName);
}
/**
* Constructor that takes the width and height
* @param width the width of the desired picture
* @param height the height of the desired picture
*/
public Picture(int width, int height)
{
// let the parent class handle this width and height
super(width,height);
}
/**
* Constructor that takes a picture and creates a
* copy of that picture
*/
public Picture(Picture copyPicture)
{
// let the parent class do the copy
super(copyPicture);
}
/**
* Constructor that takes a buffered image
* @param image the buffered image to use
*/
public Picture(BufferedImage image)
{
super(image);
}
////////////////////// methods ///////////////////////////////////////
/**
* Method to return a string with information about this picture.
* @return a string with information about the picture such as fileName,
* height and width.
*/
public String toString()
{
String output = "Picture, filename " + getFileName() +
" height " + getHeight()
+ " width " + getWidth();
return output;
}
public void grayscale()
{
Pixel[] pixelArray = this.getPixels();
Pixel pixel = null;
int intensity = 0;
for (int i = 0; i < pixelArray.length; i++)
{
pixel = pixelArray[i];
intensity = (int) ((pixel.getRed() + pixel.getGreen() + pixel.getBlue()) / 3);
pixel.setColor (new Color (intensity, intensity, intensity));
}
}
public static void main(String[] args)
{
String fileName = FileChooser.pickAFile();
Picture pictureObject = new Picture(fileName);
pictureObject.grayscale();
pictureObject.show();
}
} // this } is the end of class Picture, put all new methods before this
THIS IS WHAT THE INTERACTIONS PANEL RETURNS:
Welcome to DrJava. Working directory is C:\bookClasses
> java Picture
java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(Unknown Source)
at java.awt.image.Raster.createPackedRaster(Unknown Source)
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(Unknown Source)
at java.awt.image.BufferedImage.<init>(Unknown Source)
at SimplePicture.<init>(SimplePicture.java:84)
at SimplePicture.<init>(SimplePicture.java:60)
at Pixel.<init>(Pixel.java:36)
at SimplePicture.getPixel(SimplePicture.java:323)
at SimplePicture.setAllPixelsToAColor(SimplePicture.java:189)
at SimplePicture.<init>(SimplePicture.java:88)
at SimplePicture.<init>(SimplePicture.java:60)
at Pixel.<init>(Pixel.java:36)
at SimplePicture.getPixel(SimplePicture.java:323)
at SimplePicture.setAllPixelsToAColor(SimplePicture.java:189)
at SimplePicture.<init>(SimplePicture.java:88)
at SimplePicture.<init>(SimplePicture.java:60)
at Pixel.<init>(Pixel.java:36)
at SimplePicture.getPixel(SimplePicture.java:323)
at SimplePicture.setAllPixelsToAColor(SimplePicture.java:189)
at SimplePicture.<init>(SimplePicture.java:88)
at SimplePicture.<init>(SimplePicture.java:60)
at Pixel.<init>(Pixel.java:36)
at SimplePicture.getPixel(SimplePicture.java:323)
at SimplePicture.setAllPixelsToAColor(SimplePicture.java:189)
at SimplePicture.<init>(SimplePicture.java:88)
at SimplePicture.<init>(SimplePicture.java:60)
at Pixel.<init>(Pixel.java:36)
at SimplePicture.getPixel(SimplePicture.java:323)
at SimplePicture.setAllPixelsToAColor(SimplePicture.java:189)
at SimplePicture.<init>(SimplePicture.java:88)
at SimplePicture.<init>(SimplePicture.java:60)
at Pixel.<init>(Pixel.java:36)
>
Hi Chris, thanks for your help.
The library is the multimedia library from Georgia Tech:
http://www.developer.com/java/other/article.php/3782471/Multimedia-Programming-with-Java-Getting-Started.htm#The_multimedia_class_library
I've also tried to reproduce it on Vista and was able to convert a JPG to gray scale with the default settings.
I forgot that the stack size is a per-thread setting, so even 64m is too big. I didn't run into problems when I used 32m, but even that should be excessive (given that the default size appears to be 256k).
I can only ask to experiment with other values, such as 32m, 16m, 8m, 4m, 2m, 1m.
three classes and a picture
I have attached the classes as a zip file as you requested. Thank you.
This is not a DrJava bug. It is a bug in your program.
You are creating an infinite recursion in your own program. Look at the stack trace:
at SimplePicture.getPixel(SimplePicture.java:323)
at SimplePicture.setAllPixelsToAColor(SimplePicture.java:189)
at SimplePicture.<init>(SimplePicture.java:88)
at SimplePicture.<init>(SimplePicture.java:60)
at Pixel.<init>(Pixel.java:36)
at SimplePicture.getPixel(SimplePicture.java:323)
In SimplePicture.getPixel method, line 323, you are calling the Pixel constructor.
In Pixel extends SimplePicture, so when Pixel's constructor (line 36) gets called, it first calls the SimplePicture constructor.
The SimplePicture constructor in line 60 calls another SimplePixel constructor.
The second SimplePicture constructor calls setAllPixelsToAColor in line 88.
In line 189, setAllPixelsToAColor calls SimplePicture.getPixel, and the hole thing starts again.
Please do not file another bug report or discuss this further on this forum. Instead, refer your professor to this analysis of YOUR PROGRAMMING BUG and let him help you understand YOUR MISTAKE.
Closed for good.
I did ask the instructor. He saw the interactions output too, but did not mention anything about recursion. I'm a beginning student, so I don't know anything about recursion. He should have found that problem when he looked at it. I apologize for thinking it was a Dr. Java bug. Please understand, the instructor himself assured me it was a conflict with the operatiing system. I'm angry that he looked at it so thoroughly and did not see what you see.