Results 1 to 7 of 7
- 03-08-2012, 04:13 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
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):
Here is the error:Java 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(); } } }
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...)Last edited by pbrockway2; 03-08-2012 at 04:27 AM. Reason: code tags added
- 03-08-2012, 04:28 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,543
- Rep Power
- 11
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.
- 03-08-2012, 04:34 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,543
- Rep Power
- 11
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
Java Code:new Picture(startingPicture.morphStage(startingPicture, endingPicture, 5, 1))
- 03-08-2012, 03:07 PM #4
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
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.
Java 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++; } } } } }
- 03-08-2012, 03:56 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
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:
Java Code:new Picture(startingPicture.morphStage(startingPicture, endingPicture, 5, 1))
Please do not ask for code as refusal often offends.
- 03-08-2012, 03:59 PM #6
Member
- Join Date
- Mar 2012
- Posts
- 9
- Rep Power
- 0
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
- 03-08-2012, 04:20 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
void type not allowed here
By Nazneen Ali in forum New To JavaReplies: 1Last Post: 07-24-2011, 01:23 PM -
Issue with "void type not allowed here" and I cannot see why.
By flpanthers1 in forum New To JavaReplies: 8Last Post: 05-25-2011, 06:26 PM -
void type not allowed
By jockhip12 in forum New To JavaReplies: 6Last Post: 05-05-2011, 05:26 PM -
'void' type not allowed here
By Torgero in forum New To JavaReplies: 15Last Post: 10-04-2008, 11:08 PM -
is void a type?
By mary in forum New To JavaReplies: 3Last Post: 08-01-2007, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks