Err: 'void' type not allowed here
The code is to call the created method morphStage in order to morph one picture to another as well as display the intermediate pictures (the stages of the morphing process). I need to be able to do this for both a 5 picture sequence and an 11 picture sequence and am completely lost after hours of work only to get my error trouble.
Here is the code (errors occur in lines 33 & 38 where I am trying to make & display the intermediate pictures):
Code:
public class TestMorphing
{
public static void main(String[] args)
{
//*****Test One : Make and display a morph of a five picture sequence*****//
//Choose swan.jpg from mediasources
String start = FileChooser.pickAFile();
Picture startingPicture = new Picture(start);
int startWidth = startingPicture.getWidth();
int startHeight = startingPicture.getHeight();
//Choose twoSwans.jpg from mediasources
String end = FileChooser.pickAFile();
Picture endingPicture = new Picture(end);
int endWidth = endingPicture.getWidth();
int endHeight = endingPicture.getHeight();
if(startWidth != endWidth || startHeight != endHeight)
{
SimpleOutput.showInformation("Sorry. Your files are not of the same size.");
}
else
{
int rate = SimpleInput.getIntNumber("Enter Integer Number: ");
Picture[] pictureArray;
pictureArray = new Picture[rate + 2];
pictureArray[0] = startingPicture;
pictureArray[pictureArray.length - 1] = endingPicture;
//Making frame p1 and displaying it
Picture p1 = new Picture(startingPicture.morphStage(startingPicture, endingPicture, 5, 1));
pictureArray[1] = p1;
pictureArray[1].show();
//Making frame p2 and displaying it
Picture p2 = new Picture(startingPicture.morphStage(startingPicture,endingPicture, 5, 2));
pictureArray[2] = p2;
pictureArray[2].show();
}
}
}
Here is the error:
2 errors found:
File: C:\Users\Shawnee\TestMorphing.java [line: 33]
Error: C:\Users\Shawnee\TestMorphing.java:33: 'void' type not allowed here
File: C:\Users\Shawnee\TestMorphing.java [line: 38]
Error: C:\Users\Shawnee\TestMorphing.java:38: 'void' type not allowed here
Note: I am using DrJava (school requirement... what can you do...)
Re: Err: 'void' type not allowed here
Hi AndreaRenee, welcome to the forums! When you post code use the "code" tags: put [code] at the start of your code and [/code] at the end. That way the code will be readable when it appears here.
Re: Err: 'void' type not allowed here
I don't know anything about this Picture class, but it looks very much as if its morphStage() method is void (ie does not return anything). In that case it cannot be used as an argument to anything, as in
Code:
new Picture(startingPicture.morphStage(startingPicture, endingPicture, 5, 1))
Re: Err: 'void' type not allowed here
Sorry about the code tags... I didn't know.
Also, this is this morphStage() method I made in my Picture class... If it helps.
Code:
public void morphStage(Picture startPicture, Picture endPicture, int numStages, int k){
Picture result = new Picture(startPicture.getWidth(), startPicture.getHeight());
{
Pixel[] pixelArrayStart = startPicture.getPixels();
Pixel[] pixelArrayEnd = endPicture.getPixels();
Pixel[][][] pixelRGB = null;
Pixel pixelObjStart = null;
Pixel pixelObjEnd = null;
Pixel pixelObjNew = null;
//Colour Values for Start Photo
int redValueStart = 0;
int greenValueStart = 0;
int blueValueStart = 0;
//Colour Values for End Photo
int redValueEnd = 0;
int blueValueEnd = 0;
int greenValueEnd = 0;
//Colour Values for Intermediate Photo
int redValue = 0;
int greenValue = 0;
int blueValue = 0;
//////////////////////////
//Loop through columns
for (int y = 0; y < getHeight();)
{
//Loop through rows
for (int x = 0; x < getWidth();)
{
//Get the pixel and the colour of the pixel
pixelObjStart = this.getPixel(x,y);
redValueStart = pixelObjStart.getRed();
greenValueStart = pixelObjStart.getGreen();
blueValueStart = pixelObjStart.getBlue();
pixelObjEnd = this.getPixel(x,y);
redValueEnd = pixelObjEnd.getRed();
greenValueEnd = pixelObjEnd.getGreen();
blueValueEnd = pixelObjEnd.getBlue();
//Morphing loop
for (int i = 0; i< pixelArrayStart.length;)
{
pixelObjStart = pixelArrayStart[i];
redValue = redValueStart + ((redValueEnd - redValueStart)/(numStages + 1))*k;
greenValue = greenValueStart + ((greenValueEnd - greenValueStart)/(numStages + 1))*k;
blueValue = blueValueStart + ((blueValueEnd - blueValueStart)/(numStages + 1))*k;
pixelObjNew.setRed(redValue);
pixelObjNew.setGreen(greenValue);
pixelObjNew.setBlue(blueValue);
x++;
y++;
i++;
}
}
}
}
}
Re: Err: 'void' type not allowed here
Which, as pbrockway has already said, does not return anything ('void').
You cannot pass 'void' as a parameter to a method, or assign it to a variable...which is what you are trying to do with:
Code:
new Picture(startingPicture.morphStage(startingPicture, endingPicture, 5, 1))
Re: Err: 'void' type not allowed here
Ah well, this is what I get for being dumber than a post and apparently not knowing how to read too. Thanks for the help
Re: Err: 'void' type not allowed here
We all suffer from code blindness at times.
Goes with the territory.
:)